C语言的一个小难题

来源:百度知道 编辑:UC知道 时间:2024/09/22 23:29:13
#include <stdio.h>
#include <math.h>
main()
{
double a;
scanf("%f",&a);
printf("%f",a);
}

上面这段代码,运行以后输入1,输入的结果却是0.000,当把double改为float 以后却能够输入正确结果,请问为什么

float为单精度浮点型。
bouble为双精度浮点型
double精度是float的二倍,当运算需要的精度较高或位数较大是用double比较好
#include <stdio.h>
#include <math.h>
main()
{
double a;
scanf("%lf",&a);
printf("%lf",a);
}
这样就可以了,先来先得,给分咯。。。早起的鸟儿有虫吃........