Index « Previous Next »

Question

Write a program that prompts the user to input a Celsius temperature and outputs the equivalent temperature in Fahrenheit. The formula to convert the temperature is:
F = 9/5 C + 32
where F is the Fahrenheit temperature and C is the Celsius temperature.

Source Code

#include <stdio.h>

int main()
{
    float celsius, fahrenheit;

    printf("Enter the temperature in celcius :");
    scanf("%f", &celsius);

    /*Converting celcius to fahrenheit */
    fahrenheit = 9.0 / 5 * celsius + 32;

    printf("Temperature in fahrenheit : %0.2f", fahrenheit);

    return 0;
}

Output

Enter the temperature in celcius :37
Temperature in fahrenheit : 98.60