From 67640165f1a301225338754c12c71ba213d44255 Mon Sep 17 00:00:00 2001 From: Zhineng Li Date: Wed, 4 Feb 2026 09:49:20 +0800 Subject: ex01-15: rewrite temperature conversion program with function --- ch01/ex15-temp.c | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 ch01/ex15-temp.c 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 + +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; +} -- cgit v1.2.3