In this tutorial you will learn about the C Program to convert Fahrenheit to Celsius and its application with practical example.
C Program to convert Fahrenheit to Celsius
In this tutorial, we will learn to create a C program that will convert Fahrenheit to Celsius in C programming.
Prerequisites
Before starting with this tutorial, we assume that you are the best aware of the following C programming topics:
- Operators in C Programming.
- Basic Input and Output function in C Programming.
- Basic C Programming.
- Arithmetic Operators in C Programming.
What are Fahrenheit & Celsius?
Fahrenheit and Celsius are the two most common scales to measure the temperature. Both the scales are having different values for the measurements of temperature. The formula for conversion is given below.
1 2 3 |
<strong>Formulae for conversion F = (1.8 x C) + 32</strong> |
Algorithm:-
1 2 3 4 5 6 7 8 9 10 11 |
1. Declaring the variable for taking the input from the user. 2. Taking the input of temperature from the user from the user. 3. Passing that Fahrenheit to program for conversion. 4. Converting the <strong>Fahrenheit to Celsius</strong>. 5. Printing the converted values. 6. End Program. |
Program to convert Fahrenheit to Celsius.
In this program, we will first take the input from the user in Fahrenheit. And then we will convert that input into Celsius. Using the above table conversion formula and Printing the result.
With the help of the below program, we can convert Fahrenheit to Celsius.
Program Code:-
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
/* C Program to convert Fahrenheit to Celsius */ #include<stdio.h> int main() { //Declaring the required variables for the program float celsius,fahrenheit; //celsius = it will hold the float value for the celsius //fahrenheit = it will hold the float value for the fahrenheit //Reads temperature in fahrenheit from the user printf("\nEnter temperature in Fahrenheit:"); scanf("%f",&fahrenheit); //Fahrenheit to celsius conversion formula used to convert celsius = (fahrenheit - 32)*5/9; //Printing the resultant conversion printf("\nCelsius = %.3f",celsius); //.3f means correct to 3 decimal places return 0; } |
Output:-
In the above program, we have first initialized the required variable.
- Fahrenheit = it will hold the temperature value.
Taking the input temperature from the user in Fahrenheit.
Converting into Celsius.
Printing the output of the program.