Given with temperature ‘n’ in Fahrenheit and the challenge is to convert the given temperature to Celsius and display it.
Example
Input 1-: 132.00 Output -: after converting fahrenheit 132.00 to celsius 55.56 Input 2-: 456.10 Output -: after converting fahrenheit 456.10 to celsius 235.61
For converting the temperature from Fahrenheit to Celsius, there is a formula which is given below
T(°C) = (T(°F) - 32) × 5/9
Where, T(°C) is temperature in Celsius and T(°F) is temperature in Fahrenheit
Approach used below is as follows −
- Input temperature in a float variable let’s say Fahrenheit
- Apply the formula to convert the temperature into Celsius
- Print celsius
Algorithm
Start Step 1-> Declare function to convert Fahrenheit to Celsius float convert(float fahrenheit) declare float Celsius Set celsius = (fahrenheit - 32) * 5 / 9 return Celsius step 2-> In main() declare and set float fahrenheit = 132.00 Call convert(fahrenheit) Stop
Example
#include <stdio.h> //convert fahrenheit to celsius float convert(float fahrenheit) { float celsius; celsius = (fahrenheit - 32) * 5 / 9; return celsius; } int main() { float fahrenheit = 132.00; printf("after converting fahrenheit %.2f to celsius %.2f ",fahrenheit,convert(fahrenheit)); return 0; }
Output
IF WE RUN THE ABOVE CODE IT WILL GENERATE FOLLOWING OUTPUT
after converting fahrenheit 132.00 to celsius 55.56