Logic:
- Formula for temperature conversion is:
- C=(F-32)*5/9
- F=9/5 * C +32
Algorithm
- Enter choice ch
- if (ch == 1)
- {
- printf(“enter the value of temperature in Celcius\n”);
- scanf(“%f”, &celcius);
- f = (celcius * 9 / 5) + 32;
- printf(“the value of temperature in fahrenheit is %f”, f);
- }
- else
- {
- printf(“enter the value of temperature in fahrenheit\n”);
- scanf(“%f”, &f);
- celcius = (f – 32) * 5 / 9;
- printf(“the value of temperature in celcius is %f”, celcius);
- }
Program
#include <stdio.h> int main() { printf("*****************************************************************"); printf("\n*****************************************************************"); printf("\n** WAP to convert temp from farenheit to celcius or vice versa **"); printf("\n** using if else **"); printf("\n** Created by Sheetal Garg **"); printf("\n** Assistant Professor **"); printf("\n** Phone No:9467863365 **"); printf("\n*****************************************************************"); printf("\n*****************************************************************\n"); float celcius, f;2 int ch; printf("enter choice"); scanf("%d", &ch); if (ch == 1) { printf("enter the value of temperature in Celcius\n"); scanf("%f", &celcius); f = (celcius * 9 / 5) + 32; printf("the value of temperature in fahrenheit is %f", f); } else { printf("enter the value of temperature in fahrenheit\n"); scanf("%f", &f); celcius = (f - 32) * 5 / 9; printf("the value of temperature in celcius is %f", celcius); } return 0; }
Output 1:
***************************************************************** ***************************************************************** ** WAP to convert temp from farenheit to celcius or vice versa ** ** using if else ** ** Created by Sheetal Garg ** ** Assistant Professor ** ** Phone No:9467863365 ** ***************************************************************** ***************************************************************** enter choice 1 enter the value of temperature in Celcius 100 the value of temperature in fahrenheit is 212.000000
Output 2:
***************************************************************** ***************************************************************** ** WAP to convert temp from farenheit to celcius or vice versa ** ** using if else ** ** Created by Sheetal Garg ** ** Assistant Professor ** ** Phone No:9467863365 ** ***************************************************************** ***************************************************************** enter choice 2 enter the value of temperature in fahrenheit 212 the value of temperature in celcius is 100.000000