Q:

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

0

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.

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

 
 

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 .

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

C Basic Solved Programs – C Programming

This question belongs to these collections

Similar questions


need a help?


find thousands of online teachers now
C Program to display sum of even and product of od... >>
<< Write a C program to calculate Gross Salary of an ...