Fahrenheit to Celsius C Program

Flow Control
If-else Statement in C
Programs on if-else
Switch Case in C
Switch case Programs
Conditional Operator
While loop in C
Do-while loop in C
While vs do-while
For loop in C
Break keyword in C
Continue keyword in C
Break vs Exit in C
Goto keyword in C
☕️ Flow Control Programs
Largest in 3 Numbers
Find Grade of student
Find the absolute value
Vowel or Consonant
Leap Year Program
Simple calculator in C
Check Odd or Even 
Roots of Quadratic Equation
Find Reverse of Number
Factors of a number in C
Generate Multiplication table
Find Power of a Number
Find GCD and LCM
Find factorial of Number
Count Number of Digits
Sum of digits in Number
Sum of N Natural Numbers
Sum of Squares of Natural No.
Find Sum of Odd Numbers
Find the Sum of Series
Find Fibonacci series in C
Sum of the Fibonacci series
Sum until enters +ve numbers
Sum of max 10 no. & Skip -ve
☕️ C Conversion Programs
Celsius to Fahrenheit
Fahrenheit to Celsius
Decimal ↔ Binary
Decimal ↔ Octal
Octal ↔ Binary in C
☕️ Number Programs in C
Prime Number in C
Strong Number in C
Krishnamurthy Number
Neon Number in C
Palindrome number
Perfect Number in C
Armstrong Number
☕️ Pattern Programs in C
Pattern programs in C
Printing pattern using loops
Floyd’s triangle Program
Pascal Triangle Program
Pyramid Star Pattern in C
Diamond Pattern Programs
Half Diamond pattern in C
Print Diamond Pattern
Hollow Diamond Pattern
Diamond Pattern of Numbers

We have already seen how to convert from Celsius to Fahrenheit, in the same way, we can also convert from Fahrenheit to Celsius. The formula that will be used for this problem is given by ⁰C = (5/9) * (⁰F-32). In this post, we will write Fahrenheit to Celsius conversion C Program

#include<stdio.h>
int main()
{
   float cel, fahr;

   printf("Enter Fahrenheit value: ");
   scanf("%f", &fahr);

   cel = ((5.0/9.0) * (fahr - 32)) ;

   printf("Celsius value = %.2f\n", cel);

   return 0;
}

Output for different test-cases:-

Enter Fahrenheit value: 210
Celsius value = 98.89

Enter Fahrenheit value: 98
Celsius value = 36.67

Enter Fahrenheit value: -40
Celsius value = -40.00

The -40⁰C is equal to the -40⁰F.

Generally, we need to convert Fahrenheit to Celsius in between an interval. So, now, we will Convert to Celsius for Fahrenheit = 0,30,60,90….,500 . There are various methods, some of which are given here.

C Program to convert Fahrenheit to Celsius in a Range

Fahrenheit to Celsius C Program using While loop

The while loop can be used to convert celsius to Fahrenheit. While loop in C is a pre-test loop where the expression is evaluated then only statements are executed. It uses a test expression to control the loop. Before every iteration of the loop, the test expression is evaluated.

#include<stdio.h>
int main()
{
   float celsius, fahr ;
   int lower, upper, step ;

   lower=0, upper=500, step=30 ;
   fahr = lower ;

   while ( fahr <= upper )
   {
      celsius = (5.0/9.0) * (fahr - 32) ;

      printf("%3.0f \t %6.1f \n", fahr , celsius) ;

      fahr += step ;  // fahr = fahr + step
   }

   return 0;
}

Output:-

   0       -17.8 
  30        -1.1 
  60        15.6 
  90        32.2 
 120        48.9 
 150        65.6 
 180        82.2 
 210        98.9 
 240       115.6 
 270       132.2 
 300       148.9 
 330       165.6 
 360       182.2 
 390       198.9 
 420       215.6 
 450       232.2 
 480       248.9 

Fahrenheit to Celsius using For loop

The for loop in C programming language is a pre-test loop, where first of all initialization expression is evaluated then the condition is checked and if the condition is true then only the statements of the for loop are executed. We can use for loop to convert Fahrenheit to Celsius in a range.

#include<stdio.h>
int main()
{
  int fahr ;

  for(fahr=0 ; fahr <= 500 ; fahr = fahr + 30)
  {
     printf("%d \t %6.2f \n", fahr, (5.0/9.0) * (fahr - 32) );
  }

  return 0;
}

In the above methods, we initialized directly lower value 0, upper value 500 and step value 30. For simplicity and good programming practice, we will don’t initialized these values directly within the main() function. In Symbolic constants, names are conventionally written in uppercase so they can be readily distinguished from lower case variable names. Below is another way to write Fahrenheit to Celsius C Program

#include<stdio.h>
#define LOWER 0
#define UPPER 500
#define STEP 30
int main()
{
   int fahr ;

   for(fahr=LOWER ; fahr <= UPPER ; fahr = fahr + STEP )
   {
      printf("%d \t %6.2f \n", fahr, (5.0/9.0) * (fahr - 32) );
   }

   return 0;
}

Notice that there is no semicolon at the end of a #define line.

If you enjoyed this post, share it with your friends. Do you want to share more information about the topic discussed above or do you find anything incorrect? Let us know in the comments. Thank you!

Flow Control
If-else Statement in C
Programs on if-else
Switch Case in C
Switch case Programs
Conditional Operator
While loop in C
Do-while loop in C
While vs do-while
For loop in C
Break keyword in C
Continue keyword in C
Break vs Exit in C
Goto keyword in C
☕️ Flow Control Programs
Largest among 3 Numbers
Find Grade of student
Find the absolute value
Check Vowel or Consonant
Leap Year Program
Simple calculator in C
Check Odd or Even 
Roots of Quadratic Equation
Find Reverse of Number
Factors of a number in C
Generate Multiplication table
Find Power of a Number
Find GCD and LCM
Find factorial of Number
Count Number of Digits
Sum of digits in Number
Sum of N Natural Numbers
Sum of Squares of Natural No.
Find Sum of Odd Numbers
Find the Sum of Series
Find Fibonacci series in C
Sum of the Fibonacci series
Sum until enters +ve numbers
Sum of max 10 no. & Skip -ve
☕️ C Conversion Programs
Celsius to Fahrenheit
Fahrenheit to Celsius
Decimal ↔ Binary
Decimal ↔ Octal
Octal ↔ Binary in C
☕️ Number Programs in C
Prime Number in C
Strong Number in C
Krishnamurthy Number
Neon Number in C
Palindrome number
Perfect Number in C
Armstrong Number
☕️ Pattern Programs in C
Pattern programs in C
Printing pattern using loops
Floyd’s triangle Program
Pascal Triangle Program
Pyramid Star Pattern in C
Diamond Pattern Programs
Half Diamond pattern in C
Print Diamond Pattern
Hollow Diamond Pattern
Diamond Pattern of Numbers

Leave a Comment

Your email address will not be published. Required fields are marked *