Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*Exercise 1.15. Rewrite the temperature conversion program of Section 1.2 to use a function for conversion.*/
- #include <stdio.h>
- #define UPPER 300
- #define LOWER 0
- #define STEP 20
- void fahrconv (float celsius, int upper, int lower, int step);
- main()
- {
- char *f = "Faher", *c = "Celsi";
- float lower = LOWER, upper = UPPER, step = STEP, celsius;
- printf("%6s %5s\n", c, f);
- fahrconv(celsius, upper, lower, step);
- return 0;
- }
- void fahrconv (float celsius, int upper, int lower, int step) {
- float fahr;
- while (celsius <= UPPER) {
- fahr = ((celsius * 9.0)/5.0) + 32.0;
- printf("%6.1f %5.0f\n", celsius, fahr);
- celsius = celsius + step;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment