I have intentionally forced printf()
to print celsius
as an int
(Using %8d
format specifier for it.)
But Why this whole table (other than the first step) prints 0
and moreover why fahr
is going to be 0.0
even there is no changes made to it.
I have used gcc
compiler.
这是摄氏到华氏转换的代码:
#define LOWER 0.0F
#define UPPER 300.0F
#define STEP 20.0F
#include<stdio.h>
void main(){
float celsius, fahr;
printf("*Conversion from Celsius to Fahrenheit*\n");
printf("Celsius Scale \t Fahrenheit Scale\n");
for(celsius = LOWER; celsius <= UPPER; celsius = celsius + STEP){
fahr = (9.0f * celsius / 5.0f) + 32.0f;
printf("%8d\t\t%5.1f\n", celsius, fahr);
}
}
下表是上述代码的输出:
*Conversion from Celsius to Fahrenheit*
Celsius Scale Fahrenheit Scale
0 0.0
0 0.0
0 0.0
0 0.0
0 0.0
0 0.0
0 0.0
0 0.0
0 0.0
0 0.0
0 0.0
0 0.0
0 0.0
0 0.0
0 0.0
0 0.0