C Program to Convert Celcius to Fahrenheit and vice versa

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.*/

  1. #include<stdio.h>
  2.  
  3. main ()
  4. {
  5. float temp_c, temp_f;
  6.  
  7. printf ("Enter the value of Temperature in Celcius: ");
  8.  
  9. scanf ("%f", &temp_c);
  10.  
  11. temp_f = (1.8 * temp_c) + 32;
  12.  
  13. printf ("The value of Temperature in Fahreinheit is: %f", temp_f);
  14.  
  15. }

#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


Learn More :