C program to convert temperature from degree fahrenheit to celsius

Previous Program Next Program

Write a C program to input temperature in degree fahrenheit and convert it to degree centigrade. How to convert temperature from fahrenheit to celsius in C programming. C program for temperature conversion. Logic to convert temperature from fahrenheit to celsius in C program.

Example

Input

Temperature in fahrenheit = 205

Output

Temperature in celsius = 96.11 C

Required knowledge

Fundamentals of C, Data types, Talking user input in C

Temperature conversion formula

Formula to convert temperature from degree fahrenheit to degree celsius is given by -

Fahrenheit to celsius conversion formula

Logic to convert temperature from fahrenheit to celsius

Step by step descriptive logic to convert temperature from degree fahrenheit to degree celsius -

  1. Read temperature in fahrenheit in some variable say fahrenheit.
  2. Apply the temperature conversion formula celsius = (fahrenheit - 32) * 5 / 9.
  3. Print the value of celsius.

Program to convert temperature from fahrenheit to celsius

/**
 * C program to convert temperature from degree fahrenheit to celsius
 */

#include <stdio.h>

int main()
{
    float celsius, fahrenheit;

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

    // Fahrenheit to celsius conversion formula
    celsius = (fahrenheit - 32) * 5 / 9;

    // Print the result
    printf("%.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
Enter temperature in Fahrenheit: 205
205.00 Fahrenheit = 96.11 Celsius

Happy coding ;)

Recommended posts

Previous Program Next Program
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
< pre>< code >----Your Source Code---- < / code > < / pre > (Remove spaces from pre and code tags)

No comments:

Post a Comment