The formula for converting a temperature from Fahrenheit to Celsius is C=5/9(f-3
ID: 3864573 • Letter: T
Question
The formula for converting a temperature from Fahrenheit to Celsius is
C=5/9(f-32)
And the formula for converting from Celsius to Fahrenheit is
F=9/5*C + 32
Write a function named celsius that accepts a Fahrenheit temperature as an argument, and returns that temperature converted to Celsius. Write another function named fahrenheit that accepts a Celsius temperature as an argument, and returns that temperature converted to Fahrenheit.
Demonstrate the first function by calling it in a loop that display a table of Fahrenheit temperatures 0 through 20, and their Celsius equivalent. Demonstrate the second function by calling it in a loop that display a table of Celsius temperatures 0 through 20, and their Fahrenheit equivalent.
Explanation / Answer
C PROGRAM :
#include <stdio.h>
float celsius(float F){
return (5*(F-32))/9;
}
float farenheit(float C){
return ((9*C)/5) + 32;
}
int main(void) {
// your code goes here
printf("Converting into celsius ");
for(int i=0;i<=20;i++){
printf("%d : %fC ",i,celsius(i));
}
printf("Converting into farenheit ");
for(int i=0;i<=20;i++){
printf("%d : %fF ",i,farenheit(i));
}
return 0;
}
OUTPUT :
Converting into celsius
0 : -17.777779C
1 : -17.222221C
2 : -16.666666C
3 : -16.111111C
4 : -15.555555C
5 : -15.000000C
6 : -14.444445C
7 : -13.888889C
8 : -13.333333C
9 : -12.777778C
10 : -12.222222C
11 : -11.666667C
12 : -11.111111C
13 : -10.555555C
14 : -10.000000C
15 : -9.444445C
16 : -8.888889C
17 : -8.333333C
18 : -7.777778C
19 : -7.222222C
20 : -6.666667C
Converting into farenheit
0 : 32.000000F
1 : 33.799999F
2 : 35.599998F
3 : 37.400002F
4 : 39.200001F
5 : 41.000000F
6 : 42.799999F
7 : 44.599998F
8 : 46.400002F
9 : 48.200001F
10 : 50.000000F
11 : 51.799999F
12 : 53.599998F
13 : 55.400002F
14 : 57.200001F
15 : 59.000000F
16 : 60.799999F
17 : 62.599998F
18 : 64.400002F
19 : 66.199997F
20 : 68.000000F
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.