C program to convert temperature from degree Fahrenheit to Celsius

Write a C program to input temperature in degree Fahrenheit and convert it to degree Centigrade. How to convert temperature from degree Fahrenheit to degree Celsius in C programming. C program for temperature conversion.

Example:
Input temperature in Fahrenheit = 205
Output = 96.11 C

Required knowledge

Fundamentals of C, Data types, Talking user input in C, Temperature conversion table

Conversion formula

You can use the below formula to convert temperature from degree Fahrenheit to degree Centigrade
°C = (°F -32) * 5/9

Program

/**
 * C program to convert temperature from degree Fahrenheit to Celsius
 */

#include <stdio.h>

int main()
{
    float celsius, fahrenheit;

    // Reads temperature in Fahrenheit from user
    printf("Enter temperature in Fahrenheit: ");
    scanf("%f", &fahrenheit);

    // Converts fahrenheit to celsius
    celsius = (fahrenheit-32) * 5/9;

    printf("\n%.2f Fahrenheit = %.2f Celsius", fahrenheit, celsius);

    return 0;
}

Note: %.2f is used to print fractional values only up to two decimal places. You can also use %f to print fractional values normally up to six decimal places.

Output
X
_
Enter temperature in Fahrenheit: 205

205.00 Fahrenheit = 96.11 Celsius

Happy coding ;)


Any doubt or suggestion write here. I will try my best to help. Before posting your code you must escape it to view. To format your source code and use format highlighting, post your source code inside
< code >< pre > -- Your source code -- < /pre >< /code > (Remove spaces from pre and code tags).

No comments:

Post a Comment