C program to convert temperature from degree Celsius to Fahrenheit

Write a C program to input temperature in Celsius (centigrade) from user 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 = 212 F

Required knowledge

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

Conversion formula

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

Program

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

#include <stdio.h>

int main()
{
    float celsius, fahrenheit;

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

    // Converts temperature from celsius to fahrenheit 
    fahrenheit = ((celsius * 9)/5) + 32;

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

    return 0;
} 


Output
X
_
Enter temperature in Celsius: 100

100 Celsius = 212.00 Fahrenheit

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.

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