Table of contents
1.
Introduction
1.1.
Sample Examples
2.
Approach
2.1.
Implementation in C
2.2.
Complexity Analysis 
3.
Frequently Asked Questions
3.1.
Why is C called a mid-level programming language?
3.2.
What is the use of functions in C?
4.
Conclusion
Last Updated: Oct 15, 2024
Easy

Program to convert Celsius to Fahrenheit in C

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 Celsius to Fahrenheit. 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.

Program to convert Celsius to Fahrenheit in C

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 formula of conversion from Celsius to Fahrenheit.

Sample Examples

Example 1:

Input:
C (Temperature in Celsius) = 10

Output 
50 Fahrenheit
Explanation
(9/5) * 10 + 32 = 18 + 32 = 50

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

Example 2:

Input:
C (Temperature in Celsius) = 3

Output:
37.4 Fahrenheit
Explanation
(9/5) * 3 + 32 = 27/5 + 32 = 5.4 + 32 = 37.4


Also see, Binary to Hex Converter, And Tribonacci Series

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 Celsius to Fahrenheit
#include <stdio.h>

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

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

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

 

Output:

Input: Celsius = 2
Output: 2.00 degrees in Celsius is equal to 35.60 degrees in Fahrenheit

 

For better practice, you can implement it on the Online compiler.

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)
Since no extra space was used.
 

Also see, 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 the use of functions in C?

  • C functions are utilized in our application to prevent rewriting the same code repeatedly.
  • C functions can be called as many times as we want from wherever our application is.
  • When we break a program into functions, we can track any portion of our program.
  • C functions give the idea of reusability, i.e., they divide extensive work into smaller ones, making the C program more intelligible.

Conclusion

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

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 Code360.

Live masterclass