Added exercise 1-4
authorCian Bagshaw <cian@cianb.xyz>
Tue, 29 Nov 2022 09:09:44 +0000 (09:09 +0000)
committerCian Bagshaw <cian@cianb.xyz>
Tue, 29 Nov 2022 09:09:44 +0000 (09:09 +0000)
1/4.c [new file with mode: 0644]

diff --git a/1/4.c b/1/4.c
new file mode 100644 (file)
index 0000000..2f8bf10
--- /dev/null
+++ b/1/4.c
@@ -0,0 +1,27 @@
+/*
+       Exercise 1-4. Write a program to print the corresponding Celcius to Fahrenheit
+       table.
+       ===
+
+       F = C(9/5)+32 
+*/
+
+#include <stdio.h>
+
+int main () {
+       float fahr, cels;
+
+       int lower       = 0;
+       int upper       = 300;
+       int step        = 20;
+
+       puts("Celsius to Fahrenheit");
+       puts(" C     F");
+       
+       cels = lower;
+       while (cels <= upper) {
+               fahr = (cels * (9.0/5.0)) + 32;
+               printf("%3.0f %6.1f\n", cels, fahr);
+               cels += step;
+       }
+}