Translate

Thursday, June 4, 2015

Write a C program that will convert temperature from celcius to fahrenheit and fahrenheit to celcius. Input values from user.



#include<stdio.h>
#include<math.h>
void main()

{
    char user;
    float clcs, farn, celcius, fahrenheit;

    printf("For celsius to fahrenheit press 'a' ");
    printf("\nFor fahrenheit to celsius press 'b' \n");

    scanf("%c", &user);


    switch(user){
        case 'a':
        {
            printf("\nEnter temperature in celcius: ");
            scanf("%f", &clcs);

            fahrenheit=clcs*1.8+32;
            printf("Temperature in fahrenheit: %.2f", fahrenheit);
            break;

        }


        case 'b':
        {
            printf("\nEnter temperature in fahrenheit: ");
            scanf("%f", &farn);

            celcius=(farn-32)/1.8;
            printf("Temperature in celcius: %.2f\n", celcius);
            break;

        }


        default:
            break;

        }

}


Download source code

0 comments:

Post a Comment