From 9a193d84f112aa2bdfccc6c5137ce95aeccb1ead Mon Sep 17 00:00:00 2001 From: Kris Lamoureux Date: Wed, 3 Nov 2021 00:37:32 -0400 Subject: [PATCH] Variables and arithmetic --- 02-vars-and-math.c | 20 ++++++++++++++++++++ Makefile | 5 ++++- 2 files changed, 24 insertions(+), 1 deletion(-) create mode 100644 02-vars-and-math.c diff --git a/02-vars-and-math.c b/02-vars-and-math.c new file mode 100644 index 0000000..bd7f578 --- /dev/null +++ b/02-vars-and-math.c @@ -0,0 +1,20 @@ +#include + +/* print Fahrenheit-Celsius table + for fahr = 0, 20, ..., 300 */ +int main() +{ + int fahr, celsius; + int lower, upper, step; + + lower = 0; + upper = 300; + step = 20; + + fahr = lower; + while (fahr <= upper) { + celsius = 5 * (fahr-32) / 9; + printf("%d\t%d\n", fahr, celsius); + fahr = fahr + step; + } +} diff --git a/Makefile b/Makefile index 268703a..89ef3b6 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,7 @@ -all: hello +all: hello mathvars hello: 01-hello-world.c gcc -o ./bin/01-helloworld 01-hello-world.c + +mathvars: 02-vars-and-math.c + gcc -o ./bin/02-mathvars 02-vars-and-math.c