Aim:
To write a ‘C’ program to convert the
given temperature in degree centigrade to Fahrenheit and vice versa.
Algorithm:
1. Read the
temperature in degree Centigrade.
2. Convert the
Centigrade to Fahrenheit using the formula
F=9/5*c+32
F=9/5*c+32
3. Print the Celsius
and Fahrenheit value.
4. Read the
temperature in degree Fahrenheit.
5. Convert the
Fahrenheit to Centigrade using the
formula
C=5/9*(F-32)
C=5/9*(F-32)
6. Print the
Fahrenheit and Celsius value.
7. Stop
Program:
/* Program to convert Centigrade to
Fahrenheit and vice versa */
#include
<stdio.h>
#include<conio.h>
void main()
{
float c,f;
clrscr();
/*To convert Centigrade to Fahrenheit*/
printf("Enter the temperature in
centigrade:");
scanf("%f",&c);
f=1.8*c+32;
printf("\n\t%.2f Centigrade=%.2f
Fahrenheit",c,f);
/*To convert Fahrenheit to centigrade*/
printf("\n\nEnter the temperature
in Fahrenheit:");
scanf("%f",&f);
c=(f-32)/1.8;
printf("\n\t%.2f Fahrenheit=%.2f
Centigrade",f,c);
getch();
}
Output:
Enter the
temperature in centigrade:45
45.00 Centigrade=113.00 Fahrenheit
Enter the
temperature in Fahrenheit:114
114.00 Fahrenheit=45.56 Centigrade
No comments:
Post a Comment