In this c program, we will convert temperature input by the user in celsius to Fahrenheit. We will also write the algorithm of the c program to convert temperature from Celsius to Fahrenheit. We will first find out the basic mathematics formulas and solutions to the problem. After finding out the formula and solution to our problem, we will write the algorithm and then write a program to get the desired output.
We will get the temperature in Celsius as input from the user and then I will convert temperature in Celsius using the mathematical formula. Now, after we calculate temperature in Fahrenheit, we will display it as output on the screen.
Let’s write this c program to convert temperature from Celsius to Fahrenheit. But before that, let’s just learn about the mathematical concept we are gonna use in our program.
1. Concepts
As of now, we have taken the temperature in Celsius as input from the user and we need to convert it in Fahrenheit through a c program and display them alongside on the output screen.
The formula of the calculations:
T(°F) = T(°C) × 9/5 + 32
What are the concepts of c programming you need to learn before writing this program?
Kindly, learn these basic topics, before continuing and writing this C Program.
2. Algorithm
Here’s the algorithm of writing this C Program to convert temperature from Celsius to Fahrenheit:
- START
- INPUT CELSIUS
- FAHRENHEIT = CELSIUS * (9/5) + 32
- DISPLAY CELSIUS
- DISPLAY FAHRENHEIT
- STOP
Follow the same algorithm and let’s write the actual c program.
3. C Program to convert temperature Celsius to Fahrenheit
#include<stdio.h>
void main()
{
float celsius, fahrenheit;
printf("Enter temperature in celsius:\t");
scanf("%f", &celsius);
fahrenheit=(celsius * 9/5) + 35;
printf("Temperature in celsius \t %f \n", celsius);
printf("Temperature in fahrenheit \t %f \n", fahrenheit);
}
4. Output
As we have written out C Program, let’s have a look at the output. We are giving the input distance as 56 in celsius and now, here are the outputs.
