Title Description
Given a double precision floating point, and outputs the integer part and a fractional part.
NOTE: This does not allow tricky problem, such as strings read, and then determine the position of the decimal point. % Lf must re-read double decomposition.
Entry
A plurality of input lines, each line of a double-precision floating point number.
The fractional part of not more than six. The number may be large, but the type of guarantee is double the normal value.
Export
For each set of input data, to produce one line of output, i.e., the integer and fractional parts of the double-precision floating-point, separated by spaces, decimal places 6 decimal places.
Sample input Copy
3.5
Sample output Copy
3 0.500000
prompt
Learn about modf function, this question practice using the pointer.
Code
#include <stdio.h>
#include <math.h>
int main(){
double n=0.0,precious=0.0,inter=0;
while(scanf("%lf",&n)!=EOF)
{
precious=modf(n,&inter);
printf("%.f %lf\n",inter,precious);
}
return 0;
}