Wednesday, May 1, 2013

Converting temperature from Degree Celsius to Fahrenheit & Kelvin


The c program given below is able to convert temperature into Fahrenheit and Kelvin. When you will run the program then you will be asked to provide temperature in degree Celsius. It will be asked for the 10th line of those codes.

When you will provide the temperature then it will be store into a float type variable c by the 13th line. Later by the 16th line the temperature will be converted into Fahrenheit and will be stored into a variable f.

And soon the converted temperature will be displayed by the 19th line.

Similarly the temperature will be converted into kelvin and will be stored into the variable k by the 22nd line. Finally the temperature in kelvin will be displayed by the 25th line.
//including header file
#include<stdio.h>

//main function started
void main(){
    //declaring float type variable
    float c, f, k;

    //message to input temperature
    printf("Temperature in Degree Celsius: ");

    //storing temperature into c
    scanf("%f",&c);

    //converting to fahrenheit & storingt into f
    f=1.8*c+32;

    //displaying converted temperature
    printf("Temperature in Fahrenheit: %f",f);

    //converting temperature to kelvin & storing into k
    k=c+273;

    //displaying converted temperature
    printf("\nTemperature in Kelvin: %f",k);
}

Advertisement

No comments:

Post a Comment