Chapter 1, exercises 1.1, 1.2, and the beginning of 1.3
This commit is contained in:
parent
5524ab82a4
commit
f69b32679a
8 changed files with 64 additions and 0 deletions
25
1-2/temperature.c
Normal file
25
1-2/temperature.c
Normal 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;
|
||||
}
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue