commit 37d54fd03844efe691c257182f0e5ee18b5a5701
parent 191867eefd9aeb4e550b4bd85ba79aeb3c314cd6
Author: klewer-martin <martin.cachari@gmail.com>
Date: Sat, 6 Mar 2021 17:47:40 -0300
Update;
Diffstat:
2 files changed, 31 insertions(+), 7 deletions(-)
diff --git a/the-c-programming-language/chapter01/ex03.c b/the-c-programming-language/chapter01/ex03.c
@@ -8,16 +8,16 @@ int main (void)
int lower, upper, step;
float c, f;
-/* Celsius values; */
+/* Fahrenheit values; */
lower = 0;
- upper = 50;
- step = 2;
+ upper = 100;
+ step = 5;
- printf("Celsius to Fahrenheit\n\n");
+ printf("Fahrenheit to Celsius\n\n");
- for(c = 0; c <= upper; c += step) {
- f = (c * 9.0) / 5.0 + 32;
- printf("%5.1f°C = %5.1f°F\n", c, f);
+ for(f = 0; f <= upper; f += step) {
+ c = ((f - 32) * 5) / 9;
+ printf("%5.1f°F = %5.1f°C\n", f, c);
}
return 0;
diff --git a/the-c-programming-language/chapter01/ex04.c b/the-c-programming-language/chapter01/ex04.c
@@ -0,0 +1,24 @@
+/* Exercise 1-4 - prints a table with degrees conversion */
+
+#include <stdio.h>
+
+
+int main (void)
+{
+ int lower, upper, step;
+ float c, f;
+
+/* Celsius values; */
+ lower = 0;
+ upper = 50;
+ step = 2;
+
+ printf("Celsius to Fahrenheit\n\n");
+
+ for(c = 0; c <= upper; c += step) {
+ f = (c * 9.0) / 5.0 + 32;
+ printf("%5.1f°C = %5.1f°F\n", c, f);
+ }
+
+ return 0;
+}