Write a C program to input temperature in Celsius (centigrade) and convert to Fahrenheit. How to convert temperature from degree centigrade to degree Fahrenheit in C programming. C program for temperature conversion.
Example
Input
Temperature in Celsius = 100
Output
Temperature in Fahrenheit = 212 F
Required knowledge
Fundamentals of C, Data types, Talking user input in C
Temperature conversion formula
Temperature conversion formula from degree centigrade to fahrenheit is given by -
Logic to convert temperature from celsius to fahrenheit
The real logic of this program lies in the conversion formula. We only need to convert the above formula in C programming semantics. Below is the step by step descriptive logic to convert temperature from degree celsius to fahrenheit.
- Read temperature in celsius from user in some variable say celsius.
- Apply the formula to convert the temperature to fahrenheit. Which is fahrenheit = (celsius * 9 / 5) + 32.
- Print the value of fahrenheit.
Program to convert temperature from celsius to fahrenheit
/** * C program to convert temperature from degree celsius to fahrenheit */ #include <stdio.h> int main() { float celsius, fahrenheit; // Reads temperature in celsius printf("Enter temperature in Celsius: "); scanf("%f", &celsius); // celsius to fahrenheit conversion formula fahrenheit = (celsius * 9 / 5) + 32; printf("%.2f Celsius = %.2f Fahrenheit", celsius, fahrenheit); return 0; }
Note: %.2f is used to print fractional numbers up to two decimal places. You can also use %f to print fractional normally up to six decimal places.
Enter temperature in Celsius: 100 100 Celsius = 212.00 Fahrenheit
Happy coding ;)
Recommended posts
- Basic programming exercises index.
- C program to convert temperature from Fahrenheit to Celsius.
- C program to convert days to years, weeks and days.
- C program to convert length from centimeter to meter and kilometer.
- C program to find diameter, circumference and area of circle.
- C program to calculate power of two numbers x^y.