samir82show

c_ch01_ex03.c

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