C Language

Writing a program to convert Fahrenheit into Celsius in C

Writing a program to convert Fahrenheit into Celsius in C

In this article, we will discuss the concept of  Writing a program to convert Fahrenheit into Celsius in C language

In this post, we will learn how to write a program to Convert Fahrenheit into Celsius. Celsius is calculated using scientific equations and displayed on the screen.

Code to Convert Fahrenheit into Celsius

Convert Fahrenheit into Celsius  -#1

In this program, the user declares two variables as Celsius and Fahrenheit and initiates the value as 0.0 to variable Celsius. Then the scientific equation will convert it from Fahrenheit into Celsius in the C programming language.

Program 1

//program to convert fahrenheit into celsius in C
#include <stdio.h>

int main() {
    // declaring float variables
    float celsius,fahrenheit;
    //initializing variables for fahrenheit
    fahrenheit=32;
    //Convert fahrenheit into celsius
    celsius=((fahrenheit-32)*5/9);
    printf("The temparature in celsius is=%.2f ",celsius);

    return 0;
}

When the above code is executed, it produces the following result

The temperature in Celsius is==0.00

 

Convert Fahrenheit into Celsius  -Entered by the user-#2

In this program, the user declares two variables as Celsius and Fahrenheit. The program asks for the value from the user to Fahrenheit then the given input will convert from Fahrenheit into Celsius in the C programming language using the scientific equation.

Program 2

// C program to convert Temparature
// fahrenheit into celsius
#include <stdio.h>

int main() {
    // declaring variables
    float celsius,fahrenheit;
   //asking input for variables
     printf("Enter temparature in fahrenheit :");
    scanf("%f",&fahrenheit);
  //reading the input from user
  
    //Convert fahrenheit into celsius
    celsius=((fahrenheit-32)*5/9);
    printf("The temparature in celsius is=%.2f ",celsius);

    return 0;
}

When the above code is executed, it produces the following result

Enter temperature in Fahrenheit:212.00
The temperature in Celsius is=100.00

 

Convert Fahrenheit into Celsius  -Using the function-#3

In this program, the user declares a double variable as a parameter for Fahrenheit in the user-defined function. When the user runs the program (when calling the function), the value of Fahrenheit passes as an argument to the function.
Finally, the Celsius value is calculated and displayed on the screen using the scientific equation.

Program 3

// program to convert fahrenheit into celsius using function
//in C language
#include <stdio.h>
 float convertFahToCels(float fh){
   //defined user deined function
 return ((fh-32)*5/9);
 }
int main() {
    // declaring variables
   
    //Convert fahrenheit into celsius
      float celsius1=convertFahToCels(32.00);
    float celsius2=convertFahToCels(00.00);
    float celsius3=convertFahToCels(212.00);
    float celsius4=convertFahToCels(120.00);
    float celsius5=convertFahToCels(210.00);
  
  //display result on the screen
    printf("The temperature in Celsius is=%.2f \n",celsius1);
   printf("The temperature in Celsius is=%.2f \n",celsius2);
    printf("The temperature in Celsius is=%.2f \n",celsius3);
     printf("The temperature in Celsius is=%.2f \n",celsius4);
      printf("The temperature in Celsius is=%.2f \n",celsius5);

    return 0;
}

When the above code is executed, it produces the following result

The temperature in Celsius is=0.00
The temperature in Celsius is=-17.78
The temperature in Celsius is=100.00
The temperature in Celsius is=48.89
The temperature in Celsius is=98.89

 

Convert Fahrenheit into Celsius Using the function-Entered by the user-#4

In this program, the user declares a double variable as a parameter for Fahrenheit in the user-defined function. When the user runs the program (when calling the function), The program asks for the value from the user to Fahrenheit and the value for Fahrenheit passes as an argument to the function.
Finally, the Celsius value is calculated and displayed on the screen using the scientific equation.

Program 4

// C program to convert fahrenheit into celsius using function
#include <stdio.h>
 float convertFahToCels(float fh){
   //user deined function
 return ((fh-32)*5/9);
 //Calcuate temparature in Celsius
 }
int main() {
    // declaring variables
    float cels,fahr;
   //ask input for variables
     printf("Enter temperature in Fahrenheit :");
    scanf("%f",&fahr);
    //Convert fahrenheit into celsius
    cels=convertFahToCels(fahr);
    printf("The temperature in Celsius is=%.2f ",cels);

    return 0;
}

When the above code is executed, it produces the following result

Enter temperature in Fahrenheit:0.00
The temperature in Celsius is=-17.78

 

Similar post

Celsius into Fahrenheit in C program

Fahrenheit into Celsius in C program

Celsius into Fahrenheit in C++ program

Fahrenheit into Celsius in C++ program

 

 

Karmehavannan

Recent Posts

Using function or method to Write temperature conversion : Fahrenheit into Celsius

Using Function or Method to Write to temperature conversion: Fahrenheit into Celsius In this article,…

11 months ago

Function or method:temperature conversion from Fahrenheit into Celsius – Entered by user

Function or method of temperature conversion from Fahrenheit into Celsius In this article, we will…

11 months ago

Write temperature conversion program: Fahrenheit into Celsius

Write temperature conversion program: from Fahrenheit to Celsius In this article, we will discuss the…

11 months ago

How to write a program to convert Fahrenheit into Celsius

How to write a program to convert Fahrenheit into Celsius In this article, we will…

11 months ago

Function/method to convert Celsius into Fahrenheit -Entered by user

Function/method to convert Celsius into Fahrenheit -Entered by user In this article, we will discuss…

11 months ago

Temperature conversion: Celsius into Fahrenheit using function or method

Temperature conversion: Celsius into Fahrenheit using a function or method In this article, we will…

11 months ago

This website uses cookies.