diff options
author | Adam Carpenter <53hornet@gmail.com> | 2019-05-10 16:00:12 -0400 |
---|---|---|
committer | Adam Carpenter <53hornet@gmail.com> | 2019-05-10 16:00:12 -0400 |
commit | 2c345e0909a082b77be959a4e6166cdbdc79e067 (patch) | |
tree | 4d9ff5a2884e5b87b8c0cb8e7fa358e3a9625eb4 /ftoc.c | |
download | learning-c-2c345e0909a082b77be959a4e6166cdbdc79e067.tar.xz learning-c-2c345e0909a082b77be959a4e6166cdbdc79e067.zip |
Init.
Diffstat (limited to 'ftoc.c')
-rw-r--r-- | ftoc.c | 32 |
1 files changed, 32 insertions, 0 deletions
@@ -0,0 +1,32 @@ +#include<stdio.h> + +#define LOWER 0 // lower limit of table +#define UPPER 300 // upper limit of table +#define STEP 20 // step size + +/* + * Print Fahrenheit-Celcius table for fahr = 0, 20, ... 300. + */ +main() { + float fahr, celcius; + int lower, upper, step; + + lower = 0; // lower limit of temperature table + upper = 300; // upper limit of temperature table + step = 20; // step size + + fahr = lower; + + printf("%3s %6s\n", "F", "C"); + + // while (fahr <= upper) { + // celcius = 5.0 / 9.0 * (fahr - 32.0); + // printf("%3.0f %6.1f\n", fahr, celcius); + // fahr = fahr + step; + // } + + for (fahr = UPPER; fahr >= LOWER; fahr = fahr - STEP) { + printf("%3.0f %6.1f\n", fahr, (5.0 / 9.0) * (fahr - 32)); + } +} + |