How to write a C Program to Convert Celsius to Fahrenheit and vice versa in C Programming Language ?
Solution:
This Program converts the Temperature from Fahrenheit to Celsius and vice versa.
Temperature of a city in Fahrenheit degrees is input through the keyboard.
Write a program to convert this temperature into Centigrade degrees.
/*To convert Fahrenheit to Celsius, subtract 32 degrees and divide by 1.8.
To convert Celsius to Fahrenheit, multiply by 1.8 and add 32 degrees.*/
To convert Celsius to Fahrenheit, multiply by 1.8 and add 32 degrees.*/
- #include<stdio.h>
- main ()
- {
- float temp_c, temp_f;
- printf ("Enter the value of Temperature in Celcius: ");
- scanf ("%f", &temp_c);
- temp_f = (1.8 * temp_c) + 32;
- printf ("The value of Temperature in Fahreinheit is: %f", temp_f);
- }
#include
int main(void)
{
// Local Declarations
float Celsius, Fahrenheit, Fahrenheit_1, Celsius_2;
// Statements
printf("Enter the temperature in Fahrenheit: ");
scanf("%f", &Fahrenheit);
printf("Fahrenheit temperature is: %5.1f F\n\a", Fahrenheit);
Celsius = (100.0 / 180.0) * (Fahrenheit - 32);
printf("Celsius temperature is: %8.1f C\n\n\a", Celsius);
system("pause");
system("cls");
printf("Enter the temperature in Celsius: ");
scanf("%f", &Celsius_2);
printf("Celsius temperature is: %8.1f C\n\a", Celsius_2);
Fahrenheit_1 = 32 + (Celsius_2 * (180.0 / 100.0));
printf("Fahrenheit temperature is: %5.1f F\a", Fahrenheit_1);
system("pause");
return 0;
}// main
int main(void)
{
// Local Declarations
float Celsius, Fahrenheit, Fahrenheit_1, Celsius_2;
// Statements
printf("Enter the temperature in Fahrenheit: ");
scanf("%f", &Fahrenheit);
printf("Fahrenheit temperature is: %5.1f F\n\a", Fahrenheit);
Celsius = (100.0 / 180.0) * (Fahrenheit - 32);
printf("Celsius temperature is: %8.1f C\n\n\a", Celsius);
system("pause");
system("cls");
printf("Enter the temperature in Celsius: ");
scanf("%f", &Celsius_2);
printf("Celsius temperature is: %8.1f C\n\a", Celsius_2);
Fahrenheit_1 = 32 + (Celsius_2 * (180.0 / 100.0));
printf("Fahrenheit temperature is: %5.1f F\a", Fahrenheit_1);
system("pause");
return 0;
}// main