Code360 powered by Coding Ninjas X Code360 powered by Coding Ninjas X
Table of contents
Sample Examples
Implementation in C++
Complexity Analysis
Key takeaways
Last Updated: Mar 27, 2024

Program to convert Fahrenheit to Celsius

Master Python: Predicting weather forecasts
Ashwin Goyal
Product Manager @


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.



Sample Examples

Example 1:

F (Temperature in Fahrenheit) = 32

0 degrees in Celsius

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


Example 2:

F (Temperature in Fahrenheit) = 50

10 degrees in Celsius

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

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


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;



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

Get the tech career you deserve, faster!
Connect with our expert counsellors to understand how to hack your way to success
User rating 4.7/5
1:1 doubt support
95% placement record
Akash Pal
Senior Software Engineer
326% Hike After Job Bootcamp
Himanshu Gusain
Programmer Analyst
32 LPA After Job Bootcamp
After Job


  1. 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. 
  2. 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.
  3. 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().

Key takeaways

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. 

Also read reverse a number.

I hope you must have gained some knowledge after reading this problem, and now it is your turn to code this problem. For more such interesting problems, you can refer to our platform Coding Ninjas Studio.

Until then, Keep Learning and Keep Coding.

Previous article
C Program to Reverse a Number
Next article
Factorial Program in C
Live masterclass