From 8ba629852ea914d74a28d0410e8a14aaf9724981 Mon Sep 17 00:00:00 2001 From: Kris Lamoureux Date: Wed, 3 Nov 2021 02:09:25 -0400 Subject: [PATCH] For loop with less variables --- 02-vars-and-math.c | 18 ++++-------------- 1 file changed, 4 insertions(+), 14 deletions(-) diff --git a/02-vars-and-math.c b/02-vars-and-math.c index 2fd0e3a..1faca06 100644 --- a/02-vars-and-math.c +++ b/02-vars-and-math.c @@ -1,20 +1,10 @@ #include -/* print Fahrenheit-Celsius table - for fahr = 0, 20, ..., 300 */ +/* print Fahrenheit-Celsius table */ int main() { - float fahr, celsius; - int lower, upper, step; + int fahr; - lower = 0; - upper = 300; - step = 20; - - fahr = lower; - while (fahr <= upper) { - celsius = (5.0/9.0) * (fahr-32.0); - printf("%3.0f %6.2f\n", fahr, celsius); - fahr = fahr + step; - } + for (fahr = 0; fahr <= 300; fahr = fahr + 20) + printf("%3d %6.1f\n", fahr, (5.0/9.0)*(fahr-32)); }