float是浮点型类型,如与整数乘时会有精确丢失,,
本代码解决方法是两种:
方法1
- #include<stdio.h>
- int main(void)
- {
- float a,b,c,d;
- a=10.1;
- b=10;
- c=10;
- d=a*((float)b*(float)c);/*乘法时,b c 申明成float 浮点型*/
- system("color f2");
- printf("%.f",d);
- return 0;
- }
复制代码
方法2
- #include<stdio.h>
- int main(void)
- {
- float a,b,c,d;
- a=10.1;
- b=10.0;/*把b申明成浮点型*/
- c=10.0;/*把c申明成浮点型*/
- d=a*(b*c);
- system("color f2");
- printf("%.f",d);
- return 0;
- }
复制代码
|