Left off on exercise 1.23

This commit is contained in:
kdeng00
2020-09-06 14:45:41 -04:00
parent 74cf2bfacc
commit 2dcca73fc5
6 changed files with 246 additions and 0 deletions
+32
View File
@@ -0,0 +1,32 @@
/*
*
* Exercise 1-15. Rewrite the temperature conversion program of Section 1.2 to
* use a function for conversion.
*
* Author: Kun Deng
*/
#include <stdio.h>
#define UPPER 200
#define LOWER 0
#define STEP 10
double convert_to_celsius(double);
int main(int argc, char **argv)
{
printf("%13s %13s\n", "fahrenheit", "celsius");
for (double fahrenheit = LOWER; fahrenheit <= UPPER; fahrenheit = fahrenheit + STEP)
{
printf("%13.2f %13.2f\n", fahrenheit, convert_to_celsius(fahrenheit));
}
return 0;
}
double convert_to_celsius(double fahrenheit)
{
return ((fahrenheit - 32) * 5.0 / 9.0);
}