- 論壇徽章:
- 0
|
/*一個計(jì)算汽車行駛里程與耗油量的關(guān)系的代碼*/- #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); 計(jì)算結(jié)果為0.0
- converted_val = gallon * GTOL / mile * MTOK * 100.0;
- printf("\nLiter(s) per 100 kilometers: %.1f", converted_val);
- puts("\nDone!");
- return 0;
- }
復(fù)制代碼 請問為何代碼當(dāng)中被注釋掉的那一行里的計(jì)算結(jié)果會為0.0呢?是不是跟括號的優(yōu)先級有關(guān)呢?就算是先計(jì)算除數(shù)也應(yīng)該不會讓結(jié)果為零啊。請各位指教! |
|