C Program to convert temperature from celsius to fahrenheit
C Program to Convert Temperature from Celsius to Fahrenheit
- Write a C program to convert temperature from celsius to fahrenheit.
- Write a C program to convert temperature from fahrenheit to celsius.
Given a temperature in Celsius, we have to convert it to fahrenheit and print it on screen. To convertcelsius to fahrenheit, we will use below expression:
F =(9/5)*C + 32;
where, C is the temperature in Celsius and F is temperature in Fahrenheit.
F =(9/5)*C + 32;
where, C is the temperature in Celsius and F is temperature in Fahrenheit.
C program to convert temperature from celsius to fahrenheit
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
| /* * C program to convert temperature from celsius to fahrenheit */ #include<stdio.h> #include<conio.h> int main() { float fahren, celsius; printf ( "Enter the temperature in celsius\n" ); scanf ( "%f" , &celsius); /* convert celsius to fahreneheit * Multiply by 9, then divide by 5, then add 32 */ fahren =(9.0/5.0) * celsius + 32; printf ( "%.2fC is equal to %.2fF\n" , celsius, fahren); getch(); return 0; } |
Enter the temperature in celsius 15 15.00C is equal to 59.00F
Enter the temperature in celsius 0 0.00C is equal to 32.00F
C program to convert temperature from fahrenheit to celsius
In this program, to convert fahreneheit to celsius we are using below expression:
C = (F - 32)*(5/9);
where, F is temperature in fahreneheit and C is temperature in celsius.
C = (F - 32)*(5/9);
where, F is temperature in fahreneheit and C is temperature in celsius.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
| /* * C program to convert temperature from fahrenheit to celcius */ #include<stdio.h> #include<conio.h> int main() { float fahren, celsius; printf ( "Enter the temperature in fahrenheit\n" ); scanf ( "%f" , &fahren); /* convert fahreneheit to celsius * Subtract 32, then multiply it by 5, then divide by 9 */ celsius = 5 * (fahren - 32) / 9; printf ( "%.2fF is equal to %.2fC\n" , fahren, celsius); getch(); return 0; } |
Enter the temperature in fahrenheit 0 0.00F is equal to -17.78C
Enter the temperature in fahrenheit 98.6 98.60F is equal to 37.00C
Comments
Post a Comment