Xcode 编译C时 输入输出不一致
问题相关代码,请勿粘贴截图
#include <stdio.h>
//测试输入输出不一致问题
int main(void)
{
float a;
printf("input a num:\n");
scanf("%f",&a);
printf("%f\n",a);
printf("There are %f seconds in %f years old\n",a*3.156e+7,a);
return 0;
}
运行结果及报错内容
input a num:
9.9
9.000000
There are 284040000.000000 seconds in 9.000000 years old
Program ended with exit code: 0
保存最新程序,重新试了几次
input a num:
9.9
0.000000
There are 0.000000 seconds in 0.000000 years old
Program ended with exit code: 0
也有正确的
input a num:
9.9
9.900000
There are 312443987.960815 seconds in 9.900000 years old
Program ended with exit code: 0
我这是用的Mac XCode编译器编辑,是不是有关系?
我的解答思路和尝试过的方法
在输入2.2等其他数据时输出0.000000,why?