Advertisement
khalfella

c_ch01_ex03.c

Sep 20th, 2014
224
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.53 KB | None | 0 0
  1. /*
  2. * Exercise 1-3.
  3. * Modify the temperature conversion program to print a heading above the table.
  4. */
  5.  
  6. #include <stdio.h>
  7.  
  8. main() {
  9. float fahr, celsius;
  10. float lower, upper, step;
  11. lower = 0; /* lower limit of temperatuire scale */
  12. upper = 300; /* upper limit */
  13. step = 20; /* step size */
  14.  
  15. fahr = lower;
  16.  
  17. /* print the header */
  18. printf("%3s %7s\n", "Farh", "Celsius");
  19.  
  20. while (fahr <= upper) {
  21. celsius = (5.0/9.0) * (fahr-32.0);
  22. printf("%3.0f %6.1f\n", fahr, celsius);
  23. fahr = fahr + step;
  24. }
  25. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement