Chapter 1, exercises 1.1, 1.2, and the beginning of 1.3

This commit is contained in:
Mitch Chisholm 2026-04-22 12:48:07 -06:00
parent 5524ab82a4
commit f69b32679a
8 changed files with 64 additions and 0 deletions

BIN
1-2/temperature Executable file

Binary file not shown.

25
1-2/temperature.c Normal file
View file

@ -0,0 +1,25 @@
/*
* Print a table of Fahrenheit temperatures and their Celsius equivalents.
* From K&R 2nd ed., 1-2
*/
#include <stdio.h>
int main (void) {
int fahr, celsius;
int lower, upper, step;
lower = 0; // Lower limit of temperature scale
upper = 300; // Upper limit of temperature scale
step = 20; // Step size
fahr = lower;
while (fahr <= upper) {
celsius = 5 * (fahr-32) / 9;
printf("%d\t%d\n", fahr, celsius);
fahr = fahr + step;
}
return 0;
}

BIN
1-2/temperature2 Executable file

Binary file not shown.

25
1-2/temperature2.c Normal file
View file

@ -0,0 +1,25 @@
/*
* Print a table of Fahrenheit temperatures and their Celsius equivalents.
* From K&R 2nd ed., 1-2
*/
#include <stdio.h>
int main (void) {
int fahr, celsius;
int lower, upper, step;
lower = 0; // Lower limit of temperature scale
upper = 300; // Upper limit of temperature scale
step = 20; // Step size
fahr = lower;
while (fahr <= upper) {
celsius = 5 * (fahr-32) / 9;
printf("%3d %7d\n", fahr, celsius);
fahr = fahr + step;
}
return 0;
}