C program to convert temperature from Fahrenheit to Celsius and vice versa

By | 02.11.2016

Fahrenheit to Celsius and Celsius to Fahrenheit


Write a C program to convert temperature from Fahrenheit to Celsius and Celsius to Fahrenheit . Here’s simple C program to convert temperature from Fahrenheit to Celsius and vice versa in C Programming Language.


Below is the source code for C program to convert temperature from Fahrenheit to Celsius and vice versa which is successfully compiled and run on Windows System to produce desired output as shown below :


SOURCE CODE : :


/*  C program to convert temperature from Fahrenheit to Celsius and vice versa  */

#include <stdio.h>

int main()
{

    float fh,cl;
    int choice;

    printf("\n1: Convert temperature from Fahrenheit to Celsius.");
    printf("\n2: Convert temperature from Celsius to Fahrenheit.\n");
    printf("\nEnter your choice (1, 2): ");
    scanf("%d",&choice);

    if(choice ==1){
        printf("\nEnter temperature in Fahrenheit: ");
        scanf("%f",&fh);
        cl= (fh - 32) / 1.8;
        printf("\nTemperature in Celsius: %.2f",cl);
    }
    else if(choice==2){
        printf("\nEnter temperature in Celsius: ");
        scanf("%f",&cl);
        fh= (cl*1.8)+32;
        printf("\nTemperature in Fahrenheit: %.2f",fh);
    }
    else{
        printf("\nInvalid Choice !!!");
    }
    return 0;
}

OUTPUT : :


First Run:
    1: Convert temperature from Fahrenheit to Celsius.
    2: Convert temperature from Celsius to Fahrenheit.
    
    Enter your choice (1, 2): 1

    Enter temperature in Fahrenheit: 98.6
    
    Temperature in Celsius: 37.00

Second Run:
    1: Convert temperature from Fahrenheit to Celsius.
    2: Convert temperature from Celsius to Fahrenheit.
    
    Enter your choice (1, 2): 2

    Enter temperature in Celsius: 37.0
    
    Temperature in Fahrenheit: 98.60

Third Run:
    1: Convert temperature from Fahrenheit to Celsius.
    2: Convert temperature from Celsius to Fahrenheit.
      
    Enter your choice (1, 2): 3

    Invalid Choice !!!

Above is the source code for C program to convert the temperature from Fahrenheit to Celsius and vice versa which is successfully compiled and run on Windows System.The Output of the program is shown above .

If you found any error or any queries related to the above program or any questions or reviews , you wanna to ask from us ,you may Contact Us through our contact Page or you can also comment below in the comment section.We will try our best to reach up to you in short interval.


Thanks for reading the post…..

4.5 2 votes
Article Rating
Category: Basic Programs C Programming Tags:

About Tunde A

My name is Tunde Ajetomobi, a Tech Enthusiast and Growth Hacker. I enjoy creating helpful content that solves problem across different topics. Codezclub is my way of helping young aspiring programmers and students to hone their skills and find solutions on fundamental programming languages.

Subscribe
Notify of
guest

0 Comments
Inline Feedbacks
View all comments