Notification texts go here Contact Us Buy Now!

Mastering Temperature: C Program for Fahrenheit to Celsius Conversion

Temperature Conversion in C: Fahrenheit to Celsius and Vice Versa

Temperature Conversion in C: Fahrenheit to Celsius and Vice Versa

When it comes to weather, understanding temperature in different units is crucial. In this blog post, we'll explore a simple C program that allows you to convert temperatures between Fahrenheit and Celsius. Let's dive into the code:

#include <stdio.h>
#include <ctype.h>

int main() {
    char unit;
    float temp;

    printf("\nIs the temperature in (F) or (C)?: ");
    scanf("%c", &unit);

    unit = toupper(unit);

    if (unit == 'C') {
        printf("\nEnter the temperature in Celsius: ");
        scanf("%f", &temp);
        temp = (temp * 9 / 5) + 32;
        printf("\nThe temperature in Fahrenheit is: %.1f", temp);
    } else if (unit == 'F') {
        printf("\nEnter the temperature in Fahrenheit: ");
        scanf("%f", &temp);
        temp = (temp - 32) * 5 / 9;
        printf("\nThe temperature in Celsius is: %.1f", temp);
    } else {
        printf("\n%c is not a valid unit of measurement", unit);
    }

    return 0;
}
        

Copy and paste this C code into your favorite compiler, and you'll be able to convert temperatures effortlessly. Whether you're dealing with Celsius or Fahrenheit, this program has you covered.

Feel free to modify and experiment with the code to enhance your understanding of C programming. Happy coding!

About the Author

Coding | Riding | Music, Embracing the beauty of code, the thrill of the ride, and the rhythm of life. Let's explore the journey together!

إرسال تعليق

Cookie Consent
We serve cookies on this site to analyze traffic, remember your preferences, and optimize your experience.
Oops!
It seems there is something wrong with your internet connection. Please connect to the internet and start browsing again.
AdBlock Detected!
We have detected that you are using adblocking plugin in your browser.
The revenue we earn by the advertisements is used to manage this website, we request you to whitelist our website in your adblocking plugin.
Site is Blocked
Sorry! This site is not available in your country.
Code Copied!