khalfella

c_ch01_ex04.c

Sep 20th, 2014
250
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-4.
  3. * Write a program to print the corresponding Celsius to Fahrenheit table.
  4. */
  5.  
  6. #include <stdio.h>
  7.  
  8. main() {
  9. float fahr, celsius;
  10. float lower, upper, step;
  11. lower = -60; /* lower limit of temperatuire scale */
  12. upper = 300; /* upper limit */
  13. step = 20; /* step size */
  14.  
  15. celsius = lower;
  16.  
  17. /* print the header */
  18. printf("%7s %3s\n", "Celsius", "Farh");
  19.  
  20. while (celsius <= upper) {
  21. fahr = (9.0/5.0) * celsius + 32.0;
  22. printf("%6.1f %3.0f\n", celsius, fahr);
  23. celsius = celsius + step;
  24. }
  25. }
Advertisement
Add Comment
Please, Sign In to add comment