Convert Fahrenheit to Celsius through a C program

In this article, we would discuss how to convert Fahrenheit to Celsius through a C program. But before that, a bit about scale of temperatures.

There are three most common units to measure temperature. These are: Fahrenheit, Celsius and Kelvin.

The Customary unit of measurement of temperature is Fahrenheit, proposed by Polish Physicist Daniel Gabriel Fahrenheit in the year 1724.

Whereas, the metric unit of temperature is Celsius. Earlier, it was Centigrade scale. Later, to honor Swedish astronomer Anders Celsius it was renamed in year 1948.

Both the temperature scales i.e. Fahrenheit and Celsius use degrees to measure temperature. Whereas, in case of Kelvin – it is kelvin or K.

We will use the below formula to convert Fahrenheit to Celsius:

oCelsius = (5)*(oFahrenheit-32)/(9)

Convert Fahrenheit to Celsius through a C program

Open a text editor, we have used Nano.

nano fah-cel.c

And, append the file with following code.

#include <stdio.h>
/* Convert Fahrenheit to Celsius */

int main(void)
{
     float fah, cel;

     printf("Enter the Fahrenheit measured value: ");
     scanf("%f",&fah);

     cel = (5.0) * (fah-32) / (9.0);

     printf("The Celsius equivalent is: %f\n", cel);

}

Next, we compile the code through GNU Compiler Collection (GCC)

gcc -o fah-cel fah-cel.c

If there are any issues (i.e. errors/warnings) with code then, it will notified as this stage. If it returns with nothing then, proceed with the following –

./fah-cel

Thereafter, enter the Fahrenheit input to get the desired output in Celsius.

The Fahrenheit-Celsius code explained

#include <stdio.h> – a directive to the preprocessor

/* Convert Fahrenheit to Celsius */ – is a comment. Compiler ignores anything between /* and */.

int main(void) – The function main() returns an integer value. And, void is to specify that the function can’t be called with an argument.

float fah, cel; – variable declaration.

printf(“Enter the Fahrenheit measured value: “); – it helps us to know when and where to provide the desired input.

scanf(“%f”,&fah); – reads float input from the user.

cel = (5.0) * (fah-32) / (9.0); – the formula for conversion, self-explanatory.

printf(“The Celsius equivalent is: %f\n”, cel); – prints the required output.

In conclusion, we have discussed how to convert Fahrenheit measured value to Celsius.

Additional Info –

On July 21, 1983 – Lowest temperature (−128.6 °F or −89.2 °C ) on Earth was recorded at Vostok station. It is a Russia research station in Antarctica. Besides,

On July 10, 1913 – Highest recorded air temperature (134.1 °F or 56.7 °C) on Earth in Death Valley, United States.