khalfella

ansi_c_pg28_ch01_ex15.c

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