Solved programming problem

Temperature Calculate in C

Source code

#include<stdio.h>

int main()

{

        int temp=0;

       char x,y;

       double m,n;

       printf("PLease enter which tepm you want to enter(c/k/f): ");

       scanf(" %c",&x);

       printf("
Please Enter The value:");

       scanf("%lf",&n);

       printf("
Please enter which temp you want to convert(c/k/f):");

       scanf(" %c",&y);

       if(x=='c'  && y=='f')

       {

           temp=1;

       }

       else if (x=='c' && y=='k')

       {

           temp=2;

       }

       else if (x=='f' &&y=='k')

       {

           temp=3;

       }

       else if (x=='f' && y=='c')

       {

           temp=4;

       }

       else if (x=='k'&& y=='c')

       {

           temp=5;

       }

       else if (x=='k'&& y=='f')

       {

           temp=6;

       }

       switch(temp)

       {

       case 1:

        m=9*n/5+32;printf("
temperature:%lf
",m); break;

       case 2:

        m=n+273;printf("
temperature:%lf
",m);break;

       case 3:

        m=5*(n-32)/9+273;printf("
temperature:%lf
",m);break;

       case 4:

        m=5*(n-32)/9;printf("
temperature:%lf
",m);break;

       case 5:

        m=m-273;printf("
temperature:%lf
",m);break;

       case 6:

        m=9*(n-273)/5+32;printf("
temperature:%lf
",m);break;

       }

     

       return 0;

}

Output

PLease enter which tepm you want to enter(c/k/f): c

Please Enter The value:30

Please enter which temp you want to convert(c/k/f): k

temperature:303.000000

Join the discussion

Add your comment