以下是引用admin_xyz在2012-9-2 20:52:32的发言:
double也有随机数
./a.exe
123.456
inum is 123
fnum = 0.456000
double
ten_hex = 0;
int
inum = 0;
double
fnum = 0;
scanf ("%lf", &ten_hex);
其实我一直没搞明白double输入的时候是%lf还是%f 好在输入浮点数的时候不多
其实原因是你这里实现方法不好 我感觉应该是这样
函数名: modf
功 能: 把数分为整数和小数 (The modf function breaks down the floating-point value x into fractional and integer parts, each of which has the same sign as x. The signed fractional portion of x is returned. The integer portion is stored as a floating-point value at intptr.
)
用 法: double modf(double x, double *intptr);
程序例:
#include <math.h>
#include <stdio.h>
int main(void)
{
double fraction, integer;
double number = 100000.567;
fraction = modf(number, &integer);
printf("The whole and fractional parts of %lf are %lf and %lf\n",
number, integer, fraction);
return 0;
}
啊 百度百科复制过来就乱了 慢慢看罢