Navigation Menu

Currently the navigation bar is not functioning. Use the Blog Archive or the Google Custom Search to find content.

Wednesday 19 June 2013

C program to convert temperature from Celsius to Fahrenheit

Given below is a C program to convert temperature from Celsius to Fahrenheit.

Formula to convert Celsius to Fahrenheit :

Multiply by 9, then divide by 5, then add 32

°C x 9/5 + 32 = °F

Formula to convert Fahrenheit to Celsius :

Deduct 32, then multiply by 5, then divide by 9

((°F - 32) x 5) / 9 = °C

Example :

0°C = 32°F

22°C = 77°F

Links that you may find important :

http://en.wikipedia.org/wiki/Celsius
http://en.wikipedia.org/wiki/Fahrenheit
http://www.mathsisfun.com/temperature-conversion.html

Code :
#include <conio.h>
#include <stdio.h>
void main()
{
 float cent,faren;
 clrscr();
 printf("Enter the temperature in Celsius : ");
 scanf("%f",&cent);
 faren=cent*9.0/5.0+32.0;
 printf("\nTemperature in Fahrenheit : %6.2f",faren);//.2f prints only 2 digits after decimal
 getch();
}
Output :
Enter the temperature in Celsius : 25

Temperature in Fahrenheit :  77.00
The above program can be modified to convert Fahrenheit to Celsius.

Code :
#include <conio.h>
#include <stdio.h>
void main()
{
 float cent,faren;
 clrscr();
 printf("Enter the temperature in Fahrenheit : ");
 scanf("%f",&faren);
 cent=((faren-32.0)*5.0)/9.0;
 printf("\nTemperature in Celsius : %6.2f",cent);//.2f prints only 2 digits after decimal
 getch();
}
Output :
Enter the temperature in Fahrenheit : 25

Temperature in Celsius :  77.00
Note : The program above has been tested using TurboCPP. Leave a comment if you feel the program is incorrect and/or has errors and/or if the program and its output don't match. Please report about broken links.

No comments:

Post a Comment