Permalink
Browse files

Scripts until chapter 1.4

  • Loading branch information...
1 parent 30d8033 commit 00645ab7e33dae83f0530272edb4527165e5569b @gvnn committed Jan 23, 2012
Showing with 27 additions and 2 deletions.
  1. +10 −0 chapter1/fctable-shorter.c
  2. +14 −0 chapter1/fctable-symbolic.c
  3. +3 −2 chapter1/fctable.c
View
@@ -0,0 +1,10 @@
+#include <stdio.h>
+
+/* print Fahrenheit-Celsius table */
+main ()
+{
+ int fahr;
+
+ for(fahr = 0; fahr <= 300; fahr = fahr + 20)
+ printf("%3d %6.1f\n", fahr, (5.0/9.0)*(fahr-32));
+}
@@ -0,0 +1,14 @@
+#include <stdio.h>
+
+#define LOWER 0 /* lower limit of table */
+#define UPPER 300 /* upper limit */
+#define STEP 20 /* step size */
+
+/* print Fahrenheit-Celsius table */
+main() {
+
+ int fahr;
+
+ for(fahr = LOWER; fahr <= UPPER; fahr = fahr + STEP)
+ printf("%3d %6.1f\n", fahr, (5.0/9.0)*(fahr-32));
+}
View
@@ -4,17 +4,18 @@
for fahr = 0, 20, ..., 300 */
main ()
{
- int fahr, celsius;
+ 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\tCelsius\n");
while (fahr <= upper) {
celsius = 5 * (fahr - 32) / 9;
- printf("%d\t%d\n", fahr, celsius);
+ printf("%10.0f\t%7.1f\n", fahr, celsius);
fahr = fahr + step;
}
}

0 comments on commit 00645ab

Please sign in to comment.