作者在 2009-02-13 08:24:04 发布以下内容
The program uses the formula [ Celsius = (5/9) * (Fahrenheit - 32)] to print the following table of Fahrenheit temperatures and their centigrade or Celsius equivalents:
=============
/* print Fahrenheit - Celsius table for fahr =0, 20, ..., 300 */
#include <stdio.h>
int main(void)
{
int fahr, cels;
int low, upper, step;
low = 0;
upper = 300;
step = 20;
fahr = low;
while (fahr <= upper)
{
cels = (5.0/9.0) * (fahr - 32);
printf("%d\t%d\n", fahr, cels);
fahr += step;
}
getch();
return 0;
}
======================
/* print Fahrenheit - Celsius table for fahr = 0, 20, ..., 300;floating-point version */
#include <stdio.h>
#include <stdio.h>
int main(void)
{
float fahr, cels;
int low, upper, step;
low = 0;
upper = 300;
step = 20;
fahr = low;
while ( fahr <= upper)
{
cels = (5.0/9.0) * ( fahr - 32);
printf("%3.0f %.1f\n",fahr, cels);
fahr = fahr + step;
}
getch();
return 0;
}
{
float fahr, cels;
int low, upper, step;
low = 0;
upper = 300;
step = 20;
fahr = low;
while ( fahr <= upper)
{
cels = (5.0/9.0) * ( fahr - 32);
printf("%3.0f %.1f\n",fahr, cels);
fahr = fahr + step;
}
getch();
return 0;
}