Implement the following functions. The functions return a real number:
(a) Function Celsius returns the Celsius equivalent of a Fahrenheit temperature ((32°F − 32) ×
5/9 = 0°C).
(b) Function Fahrenheit returns the Fahrenheit equivalent of a Celsius temperature.
((0°C × 9/5) + 32 = 32°F)
In main call both functions and ask user to input value of temperature and print its equivalent.
#include <stdio.h>
int Celsius(int F) {
int C = (F -32) * 5 / 9.0 + 0.5;
return C;
}
int Fahrenheit(int C) {
int F = (C * 9 / 5.) + 32.5;
return F;
}
int main() {
int F, C;
printf("Enter temperature in Farenheit: ");
scanf("%d", &F);
C = Celsius(F);
printf("%dF = %dC\n", F, C);
printf("Enter temperature in Celsius: ");
scanf("%d", &C);
F = Fahrenheit(C);
printf("%dC = %dF\n", C, F);
return 0;
}
Comments
Leave a comment