Objective:
Write a C program to input temperature in Centigrade and convert to Fahrenheit. How to convert temperature from degree centigrade to degree Fahrenheit in C programming. Logic to convert temperature from Celsius to Fahrenheit in C.
Example
Input
Enter temperature in Celsius = 100
Output
Temperature in Fahrenheit = 212 F
Temperature conversion formula
Temperature conversion formula from degree Celsius to Fahrenheit is given by -
ºF = ( ºC * 9/5) + 32
Logic to convert temperature from Celsius to Fahrenheit
The logic of temperature conversion exists in converting mathematical formula to C expression. You just need to convert mathematical formula of temperature in C language. Rest is simple input/output.
Below is the step by step descriptive logic to convert temperature from degree Celsius to Fahrenheit.
- Input temperature in Celsius from user. Store it in some variable say celsius.
- Apply formula to convert the temperature to Fahrenheit i.e. fahrenheit = (celsius * 9 / 5) + 32.
- Print the value of fahrenheit.
%.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.
Solution Code:
//C program to convert temperature from degree celsius to fahrenheit by CodexRitik
#include <stdio.h>
int main()
{
float celsius, fahrenheit;
/* Input 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:
This Code is Verified by CodexRitik.If any error occurs then Comment correct code Below in comment box.
Disclaimer:-
The above hole problem solution is generated by the CodexRitik . if any of the query regarding this post or website fill the following contact form Thank You.
No comments: