C program to convert Celsius to Fahrenheit
In this article, you will learn the C program to convert units of measurement from Celsius to Fahrenheit. Such a type of program plays an important role in most scientific applications, as it is the most widely used temperature scale throughout the world. The Fahrenheit scale is mostly used in the United States.
In the Celsius scale, the boiling point of water is 100°C, and the freezing point is at 0°C, while in the Fahrenheit scale the boiling point of water is measured at 212°F and freezing point at 32°F.
Celsius to Fahrenheit Formula
fahrenheit = (celsius * 9 / 5) + 32
Algorithm
- Take temperature input from the user or define the temperature in a Celsius unit.
- Apply the above formula to convert Celsius to Fahrenheit.
- Print the value in Fahrenheit.
Complexity
O(1)
C program to convert Celsius to Fahrenheit
Here is a simple program to convert Celsius to Fahrenheit using the C programming language. The given program asks the user to enter the temperature in Celsius. After getting the temperature in Celsius from the user, the C program converts it to Fahrenheit.
#include<stdio.h>
int main()
{
float fahrenheit, celsius;
/* Input temperature in Celsius */
printf("Enter temperature in Celsius: ");
scanf("%f", &celsius);
fahrenheit =( (celsius*9)/5)+32;
printf("\n\nTemperature in Fahrenheit is: %f",fahrenheit);
return (0);
}
Output 1
Enter temperature in Celsius: 42.5
Temperature in Fahrenheit is: 108.500000
Output 2
Enter temperature in Celsius: 62
Temperature in Fahrenheit is: 143.600006
C program to convert Celsius to Fahrenheit using a function
Here, we have defined a function to convert from Celsius to Fahrenheit. In this first, we ask the user to provide a temperature in Celsius. After getting the temperature in Celsius from the user, call the defined function CelsiusToFahrenheit() to convert Celsius to Fahrenheit.
#include <stdio.h>
float CelsiusToFahrenheit(float c)
{
return ((c * 9.0 / 5.0) + 32.0);
}
int main()
{
float celsius, fahrenheit;
printf("Enter temperature in Celsius: ");
scanf("%f", &celsius);
//calling function
fahrenheit = CelsiusToFahrenheit(celsius);
printf("%.2f Celsius = %.2f Fahrenheit", celsius, fahrenheit);
return 0;
}
Output 1
Enter temperature in Celsius: 47
47.00 Celsius = 116.60 Fahrenheit
Related Articles
Prime factors of a number in cArmstrong number program in c
Write a program to check leap year in c
C program to find area of rectangle
Fibonacci series program in C using recursion
Write a program to find area of circle in C
C program to find greatest of three numbers
C program for addition of two numbers
C program to calculate compound interest
C program to find the ASCII value of a character
C program to convert Decimal to Octal
C program to convert decimal to binary
Write a C program to calculate Simple Interest
C program to check whether a number is even or odd
C program to reverse a number
C program to check palindrome number
C program to check whether an alphabet is a vowel or consonant
Program to find square root of a number in C
C program to check whether a number is positive or negative