/** CPU Tutorial
2. Fundamentals of 'C'
>> Question 1 : C Program to convert temperature from Fahrenheit to Celsius and vice versa.
*/

#include<stdio.h> // including standard input output library OR header
void main() // starting of main function.
{
    float fahrenheit,celsius; // Declaration of variables with type float
    int choice; // Declaration of variables with type int

    printf("1: Convert temperature from Fahrenheit to Celsius."); // Simple print statements
    printf("\n2: Convert temperature from Celsius to Fahrenheit.");
    printf("\nEnter your choice (1, 2): ");
    scanf("%d",&choice); // compile time initialization of choice variable

    if(choice ==1) // if..else if conditional statement.
    {
        printf("\nEnter temperature in Fahrenheit: ");
        scanf("%f",&fahrenheit);
        celsius= (fahrenheit - 32) / 1.8;
        printf("Temperature in Celsius: %f",celsius);
    }
    else if(choice ==2)
    {
        printf("\nEnter temperature in Celsius: ");
        scanf("%f",&celsius);
        fahrenheit= (celsius*1.8)+32;
        printf("Temperature in Fahrenheit: %f",fahrenheit);
    }
    else
    {
        printf("\nInvalid Choice !!!");
    }
}

Comments

Popular posts from this blog

Write a C Program to Find Transpose of a Matrix.