HomeC ProgrammingC program to Convert Fahrenheit to Celsius

C program to Convert Fahrenheit to Celsius

This C program first introduces itself as a “Fahrenheit to Celsius Converter”. It then provides a brief problem statement, explaining that it converts temperature from Fahrenheit to Celsius.

Problem Statement

In the program, we declare two variables fahrenheit and celsius of type float. The user is prompted to enter the temperature in Fahrenheit. The program reads the input using scanf and stores it in the fahrenheit variable.

The formula to convert Fahrenheit to Celsius is (F - 32) * 5/9. We calculate the value of celsius using this formula.

C program to Convert Fahrenheit to Celsius

#include <stdio.h>

int main() {
    // Intro
    printf("Fahrenheit to Celsius Converter\n\n");
    
    // Problem Statement
    printf("This program converts temperature from Fahrenheit to Celsius.\n\n");
    
    // Program
    float fahrenheit, celsius;
    
    // How it works
    printf("Enter temperature in Fahrenheit: ");
    scanf("%f", &fahrenheit);
    
    celsius = (fahrenheit - 32) * 5 / 9;
    
    // Input / Output
    printf("\n%.2f degrees Fahrenheit is equal to %.2f degrees Celsius.\n", fahrenheit, celsius);
    
    return 0;
}

How it works

The program then prompts the user to enter the temperature in Fahrenheit and reads the input using scanf. The entered value is stored in the fahrenheit variable.

Next, the program performs the conversion using the formula (F - 32) * 5/9, where F represents the temperature in Fahrenheit. The result is stored in the celsius variable.

Finally, the converted temperature in Celsius is displayed on the screen using printf, with the input and output values displayed with 2 decimal places.

Input / Output

C program to Convert Fahrenheit to Celsius

Share:

Leave A Reply

Your email address will not be published. Required fields are marked *

You May Also Like

This C program calculates the volume and surface area of a sphere using its radius. A sphere is a three-dimensional...
This C program converts a Roman numeral to a decimal number. Roman numerals are a system of numerical notation used...
This C program calculates the value of sin(x) using the Taylor series expansion. The Taylor series expansion is a mathematical...