在 Code::Blocks 中 c 语言的程序运行结果有误,如何处理?
資深大佬 : l9mhd 52
问题
代码 1
#include<stdio.h> int main(){ double a,b; a = 0.15; b = (int)( a*10+0.5 ); printf("%.1f",b); return 0; }
输出 1.0
代码 2
#include<stdio.h> int main(){ double a,b; a = 0.15; b = a*10+0.5; b = (int)b; printf("%.1f",b); return 0; }
输出 2.0
之后用线上编译器( https://rextester.com/l/c_online_compiler_gcc ) 测试,两段代码结果一致,都是 2.0 。
尝试解决
从官网中重新下载安装,但是问题没有解决,运行结果仍然不一致。
- 这种情况是什么原因导致的?
- 我可以做些什么?
谢谢!
大佬有話說 (9)