Prepare Interview

Mock Exams

Make Homepage

Bookmark this page

Subscribe Email Address

Language%20in%20C%20Interview%20Questions%20and%20Answers

Question: How to extract the integer part and a fractional part of a floating point number?

Answer: C function modf( ) can be used to get the integer and fractional part of a floating point.

#include "math.h"

main( )
{
double val, i, f ;
val = 5.15 ;
f = modf ( val, &i ) ;
printf ( "nFor the value %f integer part = %f and fractional part = %f",
val, i, f ) ;
}

The output of the above program will be:

For the value 5.150000 integer part = 5.000000 and fractional part =
0.150000
Is it helpful? Yes No

Most helpful rated by users:

©2024 WithoutBook