Re-implementation of exercise 1-2 as a for loop instead of a while loop and simplified printing and calculation into a single statement as demonstrated in section 1-3.
This commit is contained in:
parent
44dff59271
commit
f42b5d0b09
2 changed files with 3 additions and 5 deletions
|
|
@ -5,7 +5,7 @@
|
||||||
|
|
||||||
int main()
|
int main()
|
||||||
{
|
{
|
||||||
float fahr, celsius;
|
float fahr;
|
||||||
float lower, upper, step;
|
float lower, upper, step;
|
||||||
|
|
||||||
lower = 0; /* lower bound of temp scale*/
|
lower = 0; /* lower bound of temp scale*/
|
||||||
|
|
@ -18,11 +18,9 @@ int main()
|
||||||
printf("Temperature conversion table with 20-degree^f steps. \n");
|
printf("Temperature conversion table with 20-degree^f steps. \n");
|
||||||
printf("%4s\t%6s\n", "DegF", "DegC");
|
printf("%4s\t%6s\n", "DegF", "DegC");
|
||||||
|
|
||||||
while (fahr <= upper)
|
for (fahr = lower; fahr <=300; fahr = fahr + step)
|
||||||
{
|
{
|
||||||
celsius = (5.0/9.0) * (fahr-32);
|
printf("%4.0f\t%6.1f\n", fahr, (5.0/9.0)*(fahr-32));
|
||||||
printf("%4.0f\t%6.1f\n", fahr, celsius);
|
|
||||||
fahr = fahr + step;
|
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
BIN
KNR C/ex1_1.out
Executable file
BIN
KNR C/ex1_1.out
Executable file
Binary file not shown.
Loading…
Add table
Add a link
Reference in a new issue