C Program to Convert Celsius to Fahrenheit

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

Celsius to Fahrenheit Formula

The Celsius to Fahrenheit formula is

fahrenheit = (celsius * 1.8) + 32

If you want to learn more about this formula, then refer to 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 Code::Blocks IDE. Here is the sample run:

c program convert centigrade to fahrenheit

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

celsius to fahrenheit conversion c

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

Centigrade to Fahrenheit in C using Function

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

#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. To learn more about function, refer to Function in C tutorial.

Same Program in Other Languages

C Online Test


« Previous Program Next Program »



Like/Share Us on Facebook 😋