C Programs | IT Developer
IT Developer

C Programs



Share with a Friend

C Program: Convert Celsius to Fahrenheit

Introduction

Temperature conversion is a common real-world problem often solved using simple mathematical formulas in programming.

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

F=(9/5×C)+32

Where:

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

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

 

C Program: Convert Celsius to Fahrenheit

C

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

 

int main() {

    float celsius, fahrenheit;

 

    // Input from user

    printf("Enter temperature in Celsius: ");

    scanf("%f", &celsius);

 

    // Conversion formula

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

 

    // Output result

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

 

    return 0; // Successful termination

}

Output

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

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

Explanation :

  1. float celsius, fahrenheit;
    • Declares variables to store Celsius and Fahrenheit values.
    • float is used because temperature can have decimal values.
  2. scanf("%f", &celsius);
    • Reads Celsius value from the user.
  3. Conversion Formula
    • (celsius * 9 / 5) + 32 converts Celsius into Fahrenheit.
  4. printf("%.2f Celsius = %.2f Fahrenheit\n", celsius, fahrenheit);
    • %.2f ensures the result is printed with two decimal places.
  5. return 0;
    • Ends the program successfully.