- 论坛徽章:
- 0
|
/*一个计算汽车行驶里程与耗油量的关系的代码*/- #include <stdio.h>
- int main(void)
- {
- const float GTOL = 3.785;
- const float MTOK = 1.609;
- float mile, gallon, converted_val;
- printf("Input the mile(s) traveled: ");
- scanf("%f",&mile);
- printf("Input the gallon(s) used: ");
- scanf("%f",&gallon);
- printf("Mile(s) per gallon: %.1f",mile/gallon);
- //converted_val = gallon * GTOL / (mile * MTOK * 100.0); 计算结果为0.0
- converted_val = gallon * GTOL / mile * MTOK * 100.0;
- printf("\nLiter(s) per 100 kilometers: %.1f", converted_val);
- puts("\nDone!");
- return 0;
- }
复制代码 请问为何代码当中被注释掉的那一行里的计算结果会为0.0呢?是不是跟括号的优先级有关呢?就算是先计算除数也应该不会让结果为零啊。请各位指教! |
|