From 4ddc868da3a8d2136866f72e4c2043f165de36c5 Mon Sep 17 00:00:00 2001 From: Reina Harrington-Affine Date: Wed, 27 Aug 2025 00:13:13 +0000 Subject: [PATCH] An implementation of exercise 1-15 that I spent far too long banging my head against over an issue that turned out to be me having flipped 5 and 9 in my math. --- KNR C/ex1_14_improved.c | 2 +- KNR C/ex1_15.c | 16 ++++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) create mode 100644 KNR C/ex1_15.c diff --git a/KNR C/ex1_14_improved.c b/KNR C/ex1_14_improved.c index c51dac0..b088d37 100644 --- a/KNR C/ex1_14_improved.c +++ b/KNR C/ex1_14_improved.c @@ -61,5 +61,5 @@ int main(){ b = charCount[(i + 1)]; } -return 0; + return 0; } diff --git a/KNR C/ex1_15.c b/KNR C/ex1_15.c new file mode 100644 index 0000000..6e77a75 --- /dev/null +++ b/KNR C/ex1_15.c @@ -0,0 +1,16 @@ +#include + +//A program for converting from C to F, using a function! +float convCelsius(int fh){ + return ((fh) - 32) * (5.0 / 9.0); +} + +int main(){ + printf("%6s, %6s\n", "DEG F", "DEG C"); + for(int cFH = -200; cFH <= 400; cFH = (cFH + 10)){ + printf("%6.0d | %6.2f\n", cFH, convCelsius(cFH)); + } + return 0; +} + +