C Program to Convert Fahrenheit to Celsius - Formula & Function

Convert Fahrenheit to Celsius Using Formula

#include <stdio.h>
int main() {
    float fahrenheit, celsius;
    printf("Enter temperature in Fahrenheit: ");
    scanf("%f", &fahrenheit);
    celsius = (fahrenheit - 32) * 5 / 9;
    printf("Temperature in Celsius = %.2f\n", celsius);
    return 0;
}
Enter temperature in Fahrenheit: 100
Temperature in Celsius = 37.78
        

The Celsius temperature is computed by subtracting 32 from the Fahrenheit value and multiplying the difference by 5/9. This formula works for any numeric input.

Convert Fahrenheit to Celsius Using a Function

#include <stdio.h>
float fahrenheit_to_celsius(float f) {
    return (f - 32.0f) * 5.0f / 9.0f;
}
int main() {
    float f;
    printf("Enter temperature in Fahrenheit: ");
    scanf("%f", &f);
    printf("Temperature in Celsius = %.2f\n", fahrenheit_to_celsius(f));
    return 0;
}
Enter temperature in Fahrenheit: 50
Temperature in Celsius = 10.00
        

Encapsulating the conversion in a separate function improves reusability. The function subtracts 32 from the input, multiplies by 5/9 and returns the result.


Comments

💬 Please keep your comment relevant and respectful. Avoid spamming, offensive language, or posting promotional/backlink content.
All comments are subject to moderation before being published.


Loading comments...