C program to convert temperature from degree celsius to fahrenheit

Previous Program Next Program

Write a C program to input temperature in Celsius (centigrade) and convert to Fahrenheit. How to convert temperature from degree centigrade to degree Fahrenheit in C programming. C program for temperature conversion.

Example

Input

Temperature in Celsius = 100

Output

Temperature in Fahrenheit = 212 F

Required knowledge

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

Temperature conversion formula

Temperature conversion formula from degree centigrade to fahrenheit is given by -

Celsius to Farenheit conversion formula

Logic to convert temperature from celsius to fahrenheit

The real logic of this program lies in the conversion formula. We only need to convert the above formula in C programming semantics. Below is the step by step descriptive logic to convert temperature from degree celsius to fahrenheit.

  1. Read temperature in celsius from user in some variable say celsius.
  2. Apply the formula to convert the temperature to fahrenheit. Which is fahrenheit = (celsius * 9 / 5) + 32.
  3. Print the value of fahrenheit.

Program to convert temperature from celsius to fahrenheit

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

#include <stdio.h>

int main()
{
    float celsius, fahrenheit;

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

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

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

    return 0;
} 

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

Output
Enter temperature in Celsius: 100
100 Celsius = 212.00 Fahrenheit

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