啊哈磊_编程从这里起步

标题: 初学者 [打印本页]

作者: wx_d01zo1QI    时间: 2015-5-19 21:05
标题: 初学者
#include <stdio.h>
#include <stdlib.h>
int main()
{
        float a,b,c;
    a=5.2;
    b=3.1;
    c=a+b;
    printf("%f",c);
        system("pause");
        return 0;
}
为什么不是8.3。。。。。。。。


作者: zhuzhu81998    时间: 2015-5-19 21:05
这个应该是float类型的精度问题,写.1f只不过是四舍五入成了8.3。还是用double吧!
作者: 李掌柜    时间: 2015-5-19 21:28
这行改成printf("%.1f",c);
作者: zhuzhu81998    时间: 2015-5-19 21:40
http://www.ahalei.com/thread-7287-1-1.html
作者: zhuzhu81998    时间: 2015-5-19 21:45
[简短的教程] 为什么说”你可能从来不需要float" ?




欢迎光临 啊哈磊_编程从这里起步 (https://bbs.codeaha.com/) Powered by Discuz! X3.2