C语言如何输入小数

C语言如何输入小数如何去掉图中dos窗口小数后面的0

看不清你的程序。
如说输出,不要小数点尾部的0,可以用 %g 格式。
#include <stdio.h>
main()
{
double d;
float f;
printf("enter 1.23\n");
scanf("%lf", &d);
printf("your input is %g\n",d);
printf("enter 4.56\n");
scanf("%f", &f);
printf("your input is %g\n",f);
return 0;
}追问

非常感谢大哥

温馨提示:答案为网友推荐,仅供参考
第1个回答  2016-07-03
不要用float类型的函数,用int整型吧,
第2个回答  2020-03-11