Chapter 1-2, exercises 1-3 and 1-4
This commit is contained in:
parent
f69b32679a
commit
3a4ab22746
4 changed files with 56 additions and 0 deletions
28
1-2/temperature3.c
Normal file
28
1-2/temperature3.c
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
/*
|
||||
* Print a table of Fahrenheit temperatures and their Celsius equivalents (floating point)
|
||||
* From K&R 2nd ed., 1-2
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
int main (void) {
|
||||
float fahr, celsius;
|
||||
float lower, upper, step;
|
||||
|
||||
lower = 0; // Lower limit of temperature scale
|
||||
upper = 300; // Upper limit of temperature scale
|
||||
step = 20; // Step size
|
||||
|
||||
fahr = lower;
|
||||
|
||||
printf("FAHRENHEIT TO CELSIUS TABLE\n");
|
||||
|
||||
while (fahr <= upper) {
|
||||
celsius = (5.0/9.0) * (fahr-32.0);
|
||||
printf("%3.0f %6.5f\n", fahr, celsius);
|
||||
fahr = fahr + step;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue