Table of contents
1.
Introduction
1.1.
Fahrenheit to Celsius and Celsius to Fahrenheit Conversion Formulas
1.1.1.
1. Fahrenheit to Celsius Formula
1.1.2.
2. Celsius to Fahrenheit Formula
2.
Sample Examples
2.1.
Example 1:
2.2.
Example 2:
3.
Approach
3.1.
Implementation in C++
3.2.
Complexity Analysis
4.
Frequently Asked Questions
4.1.
Why is C called a mid-level programming language?
4.2.
What is a built-in function in C?
4.3.
What are header files, and what are their uses in C?
5.
Conclusion
Last Updated: Jan 17, 2025
Easy

Program to convert Fahrenheit to Celsius

Career growth poll
Do you think IIT Guwahati certified course can help you in your career?

Introduction

In this blog, we will discuss the solution to the problem of converting Fahrenheit to Celsius. We will code the solution to this problem in C language. But before discussing the solution to this problem, we should first try to understand the context of Fahrenheit and Celsius. After that, we will look at the conversion of Celsius to Fahrenheit.

As we all know, temperature measures the degree of hotness and coldness. Celsius and Fahrenheit are both units of temperature used to measure the temperature. Celsius is also known as centigrade, and most countries use it. On the other hand, Fahrenheit is majorly used by the United States. Celsius is represented by °C, and Fahrenheit is represented by °F. Now, we should look at the conversion formula from Fahrenheit to Celsius.                               

Program to convert Fahrenheit to Celsius

Fahrenheit to Celsius and Celsius to Fahrenheit Conversion Formulas

Temperature conversion between Fahrenheit and Celsius is a common task. Below are the formulas and their explanations:

1. Fahrenheit to Celsius Formula

C=5/9×(F−32)

 

2. Celsius to Fahrenheit Formula

F=(C×9/5​)+32

These formulas are widely used in applications requiring temperature conversions, such as weather programs or scientific computations.

Sample Examples

Example 1:

Input:
F (Temperature in Fahrenheit) = 32

Output 
0 degrees in Celsius

Explanation
(32-32) * (5/9)= 0 *(5/9) = 0

Example 2:

Input:
F (Temperature in Fahrenheit) = 50

Output:
10 degrees in Celsius

Explanation
(50-32) * (5/9) = 18 * (5/9) = 10 

You can also read about dynamic array in c and C Static Function.

Approach

The approach to this problem is straightforward:

  1. We will first take the input in the form of float value from the user, and then we will pass that input to the formula stated above.
  2. We will store the result of the formula in another float variable. 
  3. After that, we will print that output.

Implementation in C++

// C Program to Convert Fahrenheit to Celsius
#include <stdio.h>

int main() {
    float Fahrenheit, Celsius;
  
    scanf("%f", &Fahrenheit);

    /* Formula for conversion from Fahrenheit to Celsius */
    Celsius = (5*(Fahrenheit - 32)) / 9;

    printf("\n%0.2f degree in Fahrenheit is equal to %0.2f degree in Celsius\n", Fahrenheit, Celsius);
    return 0;
}
You can also try this code with Online C Compiler
Run Code

 

Output:

Input: Fahrenheit = 38

Output: 38.00 degrees in Fahrenheit is equal to 3.33 degrees in Celsius

 

Complexity Analysis

Time Complexity: O(1)

Since we are not using any loop and there are no iterations, we are doing a constant amount of work to get the answer; the time complexity is O(1).

Space Complexity: O(1)

Also see, Tribonacci Series and Short int in C Programming

Frequently Asked Questions

Why is C called a mid-level programming language?

C is a mid-level programming language because it bridges low-level and high-level computer languages. We may utilize the C language as a System programming language to create the operating system and an Application programming language to create a menu-driven customer-driven billing system. 

What is a built-in function in C?

Built functions, also known as the library functions, are supplied by the system to make a developer's life easier by supporting them in some commonly used predetermined activities. In C, for example, if we nee d to send the output of our program to the terminal, we would use print(). Some of the most widely used built-in functions of C are scanf(), printf(), strcpy, strcmp, strlen, strcat, and many more.

What are header files, and what are their uses in C?

In C, header files have the extension .h, these header files include function definitions, data type definitions, macros, and so on. The header is used to import the above definitions into the source code, this is done by using #include before the header.  For example, if your source code requires taking input from the user, doing some modification, and printing the output on the terminal, it should include the stdio.h file as #include <stdio.h>, which allows the user to take input using scanf(), and to perform some manipulations, and after that print using printf().

Conclusion

In this article, we discussed the problem of converting Fahrenheit to Celsius. We have discussed the solution to this problem and coded the solution in C language. We have also discussed the time complexity of the approach. 

Live masterclass