码迷,mamicode.com
首页 > 其他好文 > 详细

浮点数的输入/输出

时间:2015-09-17 23:25:16      阅读:228      评论:0      收藏:0      [点我收藏+]

标签:

技术分享

#include <stdio.h>
#include <math.h>
#define PI 3.1415927
int main()
{
    double r,vol;
    while (scanf ("%lf",&r)!=EOF)
    {
        vol=4.0/3*PI*r*r*r;//There is 4.0,isn‘t 4!!
        printf ("%.3f\n",vol);
    }
    return 0;
}
这里必须是4.0而不是4,如果是4的话将不能得到想要的浮点数结果,结果的小数位上将全为零,这显然与我们所期望的结果不同。












浮点数的输入/输出

标签:

原文地址:http://www.cnblogs.com/lss-bistu/p/4817815.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!