Temperature conversion in C programming

C
// Visit: pickupmyskills.com

#include <stdio.h>

int main() {
    int choice;
    float temp, convertedTemp;

    printf("Temperature Conversion\n");
    printf("1. Fahrenheit to Celsius\n");
    printf("2. Celsius to Fahrenheit\n");
    printf("Enter your choice (1 or 2): ");
    scanf("%d", &choice);

    if (choice == 1) {
        printf("Enter temperature in Fahrenheit: ");
        scanf("%f", &temp);
        convertedTemp = (temp - 32) * 5 / 9;
        printf("Temperature in Celsius: %.2f\n", convertedTemp);
    } else if (choice == 2) {
        printf("Enter temperature in Celsius: ");
        scanf("%f", &temp);
        convertedTemp = (temp * 9 / 5) + 32;
        printf("Temperature in Fahrenheit: %.2f\n", convertedTemp);
    } else {
        printf("Invalid choice! Please enter 1 or 2.\n");
    }

   
}

Output:

Enter your choice (1 or 2): 1
Enter temperature in Fahrenheit: 100
Temperature in Celsius: 37.78

Leave a Comment

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

Scroll to Top