#include <stdio.h> int main() { int chh; float aa,bc,c,f; printf("\n"); printf("1. Press 1 for Fahrenheit to Celsius conversion \n"); printf("2. Press 2 for Celsius to Fahrenheit conversion\n"); scanf("%d", &chh); switch(chh) { case 1: printf("\n Enter the temperature in Fahrenheit : "); scanf("%f",&aa); c = 5 * (aa-32) / 9; printf("\n \n Temperature in Celsius is :%f ", c); break; case 2: printf("\n Enter the temperature in Celsius : "); scanf("%f",&bc); f = ( ( 9 * bc ) / 5 ) + 32; printf("\n \n Temperature in Fahrenheit is: %f", f); break; default: printf("\n\n This is Wrong Choice.....Try Again later!!!\n"); } return(0); }
Output: 1. Press 1 for Fahrenheit to Celsius conversion 2. Press 2 for Celsius to Fahrenheit conversion 2 Enter the temperature in Celsius : 60 Temperature in Fahrenheit is: 140
Code Analysis: To convert temperature fahrenheit to celsius following formula is used: f = ( ( 9 * bc ) / 5) +32 Where, bc is temperature in centigrade. To convert temperature celsius to fahrenheit following formula is used: c = 5 * ( aa - 32) / 9 Where, aa is temperature in fahrenheit. In the above code, program is giving three choice to the user as follows: Press 1 for Fahrenheit to Celsius conversion Press 2 for Celsius to Fahrenheit conversion Last choice is to exit.
Leave a Reply