knr/1-2/temperature.c

25 lines
491 B
C

/*
* Print a table of Fahrenheit temperatures and their Celsius equivalents.
* From K&R 2nd ed., 1-2
*/
#include <stdio.h>
int main (void) {
int fahr, celsius;
int lower, upper, step;
lower = 0; // Lower limit of temperature scale
upper = 300; // Upper limit of temperature scale
step = 20; // Step size
fahr = lower;
while (fahr <= upper) {
celsius = 5 * (fahr-32) / 9;
printf("%d\t%d\n", fahr, celsius);
fahr = fahr + step;
}
return 0;
}