/* * temperature_conversion_function.c * * Rewrite the temperature conversion program to use a function. * K&R Exercise 1.15 */ #include #define LOWER -100 #define UPPER 100 #define STEP 10 float celsius2fahrenheit(float celsius); int main() { float celsius, fahr; celsius = LOWER; while (celsius <= UPPER) { fahr = celsius2fahrenheit(celsius); /* * printf modifiers: * %f floats * %d ints * * special characters: * \n newline * \t tab * * width.precision for %f */ printf("Celsius: %6.1f\t Fahrenheit: %6.1f\n", celsius, fahr); celsius = celsius + STEP; } return 0; } float celsius2fahrenheit(float celsius) { return 9.0/5.0 * celsius + 32.0; }