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

Conversion from Celsius to Fahrenheit and from Fahrenheit to Celsius has an important role in the conversion of units system. The formula used to convert from Celsius to Fahrenheit is given by ⁰F= (⁰C * 9/5) + 32; In this post, we will write Celsius to Fahrenheit conversion C Program.

Convert Celsius to Fahrenheit using the C Program

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

  printf("Enter Celsius value: ");
  scanf("%f",&cel);

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

  printf("Fahrenheit value = %.2f", fahr);

  return 0;
}

Output for different test-cases:-

Enter Celsius value: 30
Fahrenheit value = 86.00

Enter Celsius value: 37
Fahrenheit value = 98.60

Enter Celsius value: -40
Fahrenheit value = -40.00

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

Generally, we need to convert Celsius to Fahrenheit in between a range. So, now we will Convert Celsius to Fahrenheit for Celsius = 0,20,40,60,….,200. There are various methods, some of which are given here.

C Program to Convert Celsius to Fahrenheit In a Range

Celsius to Fahrenheit 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 cel, fahr ;
   int lower, upper, step ;

   lower=0, upper=200, step=20 ;
   cel = lower ;

   while( cel <= upper )
   {
      fahr= ( cel * (9.0/5.0) ) + 32 ;

      printf("%3.0f \t %4.2f \n", cel, fahr ) ;

      cel += step ;
   }

   return 0;
}

Output:-

   0      32.00 
  20      68.00 
  40      104.00 
  60      140.00 
  80      176.00 
 100      212.00 
 120      248.00 
 140      284.00 
 160      320.00 
 180      356.00 
 200      392.00 

Celsius to Fahrenheit C program 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 Celsius to Fahrenheit in a range.

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

  for(cel=0 ; cel <= 200 ; cel = cel + 20)
  {
      printf("%d \t %4.2f \n", cel, ( cel * (9.0/5.0) ) + 32);
  }

  return 0;
}

In the above methods, we initialized directly lower value 0, upper value 200 and step value 20. 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 Celsius to Fahrenheit C Program

#include<stdio.h>
#define LOWER 0
#define UPPER 200
#define STEP 20
int main()
{
   int cel;

   for(cel=LOWER ; cel <= UPPER ; cel = cel + STEP)
   {
      printf("%d \t %4.2f \n", cel, ( cel * (9.0/5.0) ) + 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 *