Skip to content

Commit

Permalink
Exercise 1-3 and restructure
Browse files Browse the repository at this point in the history
  • Loading branch information
soffes committed Dec 25, 2009
1 parent 2418e3d commit 6b2d86a
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 2 deletions.
2 changes: 1 addition & 1 deletion section-1.1.c → examples/1.1-1.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// From page 6
// Section 1.1 Example 1 from page 6

#include <stdio.h>

Expand Down
2 changes: 1 addition & 1 deletion section-1.2.c → examples/1.2-1.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// From page 9
// Section 1.2 Example 1 from page 9

#include <stdio.h>

Expand Down
22 changes: 22 additions & 0 deletions examples/1.2-2.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// Section 1.2 Example 2 from page 12

#include <stdio.h>

/* print Fahrenheit-Celsius table
for fahr = 0, 20, ..., 300; floating-point version */
main()
{
float fahr, celsius;
int lower, upper, step;

lower = 0; /* lower limit of temperature table */
upper = 300; /* upper limit */
step = 20; /* step size */

fahr = lower;
while (fahr <= upper) {
celsius = (5.0/9.0) * (fahr-32.0);
printf("%3.0f %6.1f\n", fahr, celsius);
fahr = fahr + step;
}
}
25 changes: 25 additions & 0 deletions exercises/1-3.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// Exercise 1-3 from page 13

#include <stdio.h>

/* print Fahrenheit-Celsius table
for fahr = 0, 20, ..., 300; floating-point version */
main()
{
float fahr, celsius;
int lower, upper, step;

lower = 0; /* lower limit of temperature table */
upper = 300; /* upper limit */
step = 20; /* step size */

fahr = lower;
printf("Fahrenheit | Celsius\n");
printf("-----------|--------\n");

while (fahr <= upper) {
celsius = (5.0/9.0) * (fahr-32.0);
printf("%6.1f | %6.1f\n", fahr, celsius);
fahr = fahr + step;
}
}

0 comments on commit 6b2d86a

Please sign in to comment.