Page 27

Rewrite the temperature conversion program of Section 1.2 to use a function for conversion.

#include <stdio.h>

float get_cel(float fahr);

int main()
{
	float fahr, celsius;
	float lower, upper, step;

	lower = 0;
	upper = 300;
	step = 20;

	fahr = lower;
	while (fahr <= upper) {
		printf("%3.0f\t%6.1f\n", fahr, get_cel(fahr));
		fahr = fahr + step;
	}
}

float get_cel(float fahr)
{
	return (5.0 / 9.0) * (fahr - 32.0);
}