write a program to make celsius to fahrenheit and fahrenheit to celsius converter || Using if else ||.

 

write a program to make celsius to fahrenheit and fahrenheit to celsius converter..


#include<stdio.h>
int main(){
    char unit;
    float c,f;
    printf("Choose your unit: Enter 'c' for Celsius or 'f' for Fahrenheit\n");
    scanf(" %c", &unit);
    
    if (unit == 'c') 
    {
        printf("Enter the value of Fahrenheit: ");
        scanf("%f", &f);
       c =  (f - 32) * 5/9;
       printf("%.2f °C ", c);
    }
    else if (unit == 'f'){
        printf("Enter the value of Celsius: ");
        scanf("%f", &c);
        f = (c * 9/5) + 32;
         printf("%.2f °F ", f);
    }
    else {
        printf("Invalid choice. Please enter c for Celsius or f for Fahrenheit.\n");
    }
    return 0;
    
}

output 

Choose your unit: Enter 'c' for Celsius or 'f' for Fahrenheit
c
Enter the value of Fahrenheit: 12
-11.11 °C 

And 

Choose your unit: Enter 'c' for Celsius or 'f' for Fahrenheit
f
Enter the value of Celsius: 12
53.60 °F 

إرسال تعليق