diff options
| author | Zhineng Li <[email protected]> | 2026-02-04 09:49:20 +0800 |
|---|---|---|
| committer | Zhineng Li <[email protected]> | 2026-02-04 09:49:20 +0800 |
| commit | 67640165f1a301225338754c12c71ba213d44255 (patch) | |
| tree | 654fec4862e0f0b3971bc7747393bace45ef6c69 | |
| parent | 93e7fd1dba8a971718c085c2dee85d1e31981dea (diff) | |
| download | c-knr-exercises-67640165f1a301225338754c12c71ba213d44255.tar.gz c-knr-exercises-67640165f1a301225338754c12c71ba213d44255.zip | |
ex01-15: rewrite temperature conversion program with function
| -rw-r--r-- | ch01/ex15-temp.c | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/ch01/ex15-temp.c b/ch01/ex15-temp.c new file mode 100644 index 0000000..e38bdf4 --- /dev/null +++ b/ch01/ex15-temp.c @@ -0,0 +1,25 @@ +#include <stdio.h> + +int ftoc(int lower, int upper, int step); + +/* print Fahrenheit-Celsius table */ +int main() +{ + ftoc(0, 300, 20); + return 0; +} + +/* ftoc: print Farenheit-Celsius table */ +int ftoc(int lower, int upper, int step) +{ + float fahr, celsius; + + fahr = lower; + while (fahr <= upper) { + celsius = (5.0/9.0) * (fahr-32.0); + printf("%3.0f %6.1f\n", fahr, celsius); + fahr = fahr + step; + } + + return 0; +} |
