显然这只是代码的一小部分。是否可以使用printf语句来舍入double对象?
printf("Please enter a positive number that has a fractional part with three or more decimal places\n");
scanf("%5.2d", &x);
printf("The number you have entered is %5.2d\n" ,x);
这会自动舍入我输入的数字吗?还是有另一种方法来做到这一点?
编辑:
printf("Please enter a positive number that has a fractional part with three or more decimal places\n");
scanf("%lf", &x);
x = x + 0.05;
printf("The number you have entered is %5.2lf\n", x);
㈣做到了这一点,但是我考虑到有关的printf只是“改变”所说的话的人的方式,读出。所以这显然不是正确的方法。我应该实现可能的pow()函数吗?不知怎的,这会起作用吗?
EDIT2:
printf("Please enter a positive number that has a fractional part with three or more decimal places\n");
scanf("%lf", &x);
x = x + 0.05;
printf("The number you have entered is %5.2lf\n", x);
好的,静脉得到的地方,如果我开关输入的数,将舍入到整数的点。 35.21轮到35轮,35.51轮到36轮。等等。
我怎样才能得到35.2178加到35.22和35.2135加到35.21。 我如何获得小数的某些幂而不是整数?
是'x'是一个int还是double? – 2009-09-30 20:45:58
我已经尝试过了,它只在某些时候有效。有没有另外一种方法可以做到这一点?我对C相对比较陌生。 – Chandler 2009-09-30 20:46:18
X是在这个 – Chandler 2009-09-30 20:46:54