C Programs | IT Developer
IT Developer

C Programs



Share with a Friend

C Program: Convert Fahrenheit to Celsius

Introduction

Temperature conversion is one of the simplest yet practical problems in programming.

The formula to convert Fahrenheit (°F) to Celsius (°C) is:

C=((F−32)×5)/9

Where:

  • F = Temperature in Fahrenheit
  • C = Temperature in Celsius

In this program, we take input in Fahrenheit from the user and apply the above formula to display its equivalent in Celsius.

 

C Program: Convert Fahrenheit to Celsius

C

#include <stdio.h>   // Standard I/O header

 

int main() {

    float fahrenheit, celsius;

 

    // Input from user

    printf("Enter temperature in Fahrenheit: ");

    scanf("%f", &fahrenheit);

 

    // Conversion formula

    celsius = (fahrenheit - 32) * 5 / 9;

 

    // Output result

    printf("%.2f Fahrenheit = %.2f Celsius\n", fahrenheit, celsius);

 

    return 0; // Successful termination

}

Output

 
OUTPUT 1 :
Enter temperature in Fahrenheit: 98.6
98.60 Fahrenheit = 37.00 Celsius

OUTPUT 2 :
Enter temperature in Fahrenheit: 32
32.00 Fahrenheit = 0.00 Celsius

Explanation :

  1. float fahrenheit, celsius;
    • Declares two floating-point variables for storing temperatures.
  2. scanf("%f", &fahrenheit);
    • Reads a Fahrenheit value from the user.
  3. Conversion Formula
    • (fahrenheit - 32) * 5 / 9 converts Fahrenheit into Celsius.
  4. printf("%.2f Fahrenheit = %.2f Celsius\n", fahrenheit, celsius);
    • Displays result with two decimal places using %.2f.
  5. return 0;
    • Exits the program successfully.