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/temperature4.c
Normal file
28
1-2/temperature4.c
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
/*
|
||||
K&R C 2nd Edition, exercise 1-4
|
||||
Convert Celsius temperatures to Fahrenheit (floating point)
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
int main(void) {
|
||||
float fahr, celsius;
|
||||
float upper, lower, step;
|
||||
|
||||
upper = 200;
|
||||
lower = 0;
|
||||
step = 10;
|
||||
|
||||
celsius = lower;
|
||||
|
||||
printf("Celsius to Fahrenheit conversion table\n\n");
|
||||
|
||||
while (celsius <= upper) {
|
||||
fahr = celsius * (9.0/5.0) + 32.0;
|
||||
printf("%6.0f %6.2f\n", celsius, fahr);
|
||||
celsius = celsius + step;
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue