program to convert temperature from Fahrenheit to Celsius
Write a C program to input temperature in degree fahrenheit and
convert it to degree centigrade. How to convert temperature from fahrenheit to
celsius in C programming. C program for temperature conversion. Logic to
convert temperature from fahrenheit to celsius in C program.
Example
Input
Temperature in fahrenheit = 205
Output
Temperature conversion
formula
Formula to convert temperature from degree fahrenheit to degree celsius is given by -
Logic to convert
temperature from fahrenheit to celsius
Step by step descriptive
logic to convert temperature from degree fahrenheit to degree celsius -
1.
Read temperature in fahrenheit in some variable say fahrenheit.
2.
Apply the temperature conversion formula celsius =
(fahrenheit - 32) * 5 / 9.
3.
Print the value of celsius.
Program to convert
temperature from fahrenheit to 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
degree fahrenheit to celsius
*/
#include <stdio.h>
int main()
{
float celsius, fahrenheit;
// Reads temperature
in fahrenheit
printf("Enter
temperature in Fahrenheit: ");
scanf("%f",
&fahrenheit);
// Fahrenheit to
celsius conversion formula
celsius = (fahrenheit
- 32) * 5 / 9;
// Print the result
printf("%.2f
Fahrenheit = %.2f Celsius", fahrenheit, celsius);
return 0;
}
|
Note: %.2f is used to print fractional values only up to
two decimal places. You can also use %f to print fractional
values normally up to six decimal places.
Output
Enter temperature in Fahrenheit: 205
205.00 Fahrenheit = 96.11 Celsius
Happy coding ;)
Comments
Post a Comment