C Program to Convert Celsius to Fahrenheit

In this article, you will learn and get code about the conversion of temperature values from degrees Celsius to degrees Fahrenheit, with and without using a user-defined function.

Celsius to Fahrenheit Conversion Formula

The Celsius to Fahrenheit conversion formula is

`fahrenheit = (celsius * 1.8) + 32`

If you want to learn more about this formula, then refer to the Celsius to Fahrenheit Formula explanation. Now let's move on and implement it in a C program.

Celsius to Fahrenheit in C

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

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

This program is compiled and executed using the Code::Blocks IDE. Here is the sample run:

Now supply any temperature value (in Celsius), say 37, and press the ENTER key to see the output as given in the following snapshot:

The %0.2f format specifier is used to print the value of Fahrenheit up to 2 decimal places only.

Using Function, convert Centigrade to Fahrenheit in C

Let's create another program that does the same job as the previous program. This program is created using user-defined functions:

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

You will see the same output produced by this program.

The same program in different languages

C Quiz

« Previous Program Next Program »

Liked this post? Share it!