Write a C program to input temperature in degree fahrenheit and convert it to degree centigrade. How to convert temperature from fahrenheit to celsius in C programming. C program for temperature conversion. Logic to convert temperature from fahrenheit to celsius in C program.
Example
Input
Temperature in fahrenheit = 205
Output
Temperature in celsius = 96.11 C
Required knowledge
Fundamentals of C, Data types, Talking user input in C
Temperature conversion formula
Formula to convert temperature from degree fahrenheit to degree celsius is given by -
Logic to convert temperature from fahrenheit to celsius
Step by step descriptive logic to convert temperature from degree fahrenheit to degree celsius -
- Read temperature in fahrenheit in some variable say fahrenheit.
- Apply the temperature conversion formula celsius = (fahrenheit - 32) * 5 / 9.
- Print the value of celsius.
Program to convert temperature from fahrenheit to celsius
/** * C program to convert temperature from degree fahrenheit to celsius */ #include <stdio.h> int main() { float celsius, fahrenheit; // Reads temperature in fahrenheit printf("Enter temperature in Fahrenheit: "); scanf("%f", &fahrenheit); // Fahrenheit to celsius conversion formula celsius = (fahrenheit - 32) * 5 / 9; // Print the result printf("%.2f Fahrenheit = %.2f Celsius", fahrenheit, celsius); return 0; }
Note: %.2f is used to print fractional values only up to two decimal places. You can also use %f to print fractional values normally up to six decimal places.
Output
Enter temperature in Fahrenheit: 205 205.00 Fahrenheit = 96.11 Celsius
Happy coding ;)