# C Program to Convert Fahrenheit to Celsius

In this article, you will learn and get code about conversion of temperature value from Fahrenheit to Celsius. Before going to the program, let's understand about its formula used in conversion.

### Fahrenheit to Celsius Formula

The Fahrenheit to Celsius Formula is:

`celsius = (fahrenheit-32)*(100/180)`

To learn more about this formula, then refer to Celsius to Fahrenheit Formula explanation. There you will get complete understanding about, how this formula derived. I know that the title is for Celsius to Fahrenheit, but don't care about it, you automatically understand about Fahrenheit to Celsius formula after reading that article.

The formula given above can also be written as:

`celsius = (fahrenheit-32)/(180/100)`

And as the value of 180/100 is 1.8, so the previous formula can be further written as:

`celsius = (fahrenheit-32)/1.8`

Now let's move on to the program written in C for the conversion of Fahrenheit to Celsius.

## Fahrenheit to Celsius in C

The question is, write a program in C that converts temperature given in degree Fahrenheit to temperature in degree Celsius. The answer to this question is given below:

```#include<stdio.h>
#include<conio.h>
int main()
{
float fahrenheit, celsius;
printf("Enter Temperature Value (in Fahrenheit): ");
scanf("%f", &fahrenheit);
celsius = (fahrenheit-32)/1.8;
printf("\nEquivalent Temperature (in Celsius) = %0.2f", celsius);
getch();
return 0;
}```

This program is compiled and executed in Code::Blocks IDE. Let's have a look at the sample run of above program:

Now supply any temperature value (in Fahrenheit) say 98.6 and press ENTER key to see the following output:

Note - %0.2f format specifier is used to print decimal value upto 2 decimal place.

## Fahrenheit to Celsius in C using Function

Let's create another program that does the same job as of previous program. But this time, it is created using user-defined function. This function takes the value of Fahrenheit as its parameter and converts it into Celsius, then passes it as its return value. To learn more about function, refer to Function in C tutorial.

```#include<stdio.h>
#include<conio.h>
float fahToCelFun(float);
int main()
{
float fahrenheit, celsius;
printf("Enter Temperature Value (in Fahrenheit): ");
scanf("%f", &fahrenheit);
celsius = fahToCelFun(fahrenheit);
printf("\nEquivalent Temperature (in Celsius) = %0.2f", celsius);
getch();
return 0;
}
float fahToCelFun(float fah)
{
return ((fah-32)/1.8);
}```

The output produced by above program is same as of first program given at early of this article.

#### Same Program in Other Languages

C Online Test

« Previous Program Next Program »