samir82show

c_ch01_ex15.c

Sep 26th, 2014
177
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.75 KB | None | 0 0
  1. /*Exercise 1.15. Rewrite the temperature conversion program of Section 1.2 to use a function for conversion.*/
  2. #include <stdio.h>
  3. #define UPPER 300
  4. #define LOWER 0
  5. #define STEP 20
  6. void fahrconv (float celsius, int upper, int lower, int step);
  7. main()
  8. {
  9. char *f = "Faher", *c = "Celsi";
  10. float lower = LOWER, upper = UPPER, step = STEP, celsius;
  11. printf("%6s %5s\n", c, f);
  12. fahrconv(celsius, upper, lower, step);
  13. return 0;
  14. }
  15. void fahrconv (float celsius, int upper, int lower, int step) {
  16. float fahr;
  17. while (celsius <= UPPER) {
  18. fahr = ((celsius * 9.0)/5.0) + 32.0;
  19. printf("%6.1f %5.0f\n", celsius, fahr);
  20. celsius = celsius + step;
  21. }
  22. }
Advertisement
Add Comment
Please, Sign In to add comment