Skip to content
Menu
Code for Java c
  • Home
  • Java
    • Java Examples
    • Java tutorials
  • C
    • C tutorials
    • C Examples
  • C++
    • C++ Tutorials
    • C++ Examples
  • Python
    • Python Tutorials
    • Python Examples
  • About
    • About me
    • contact us
    • disclaimer
    • Privacy Policy
Code for Java c
Function/method to convert Celsius into Fahrenheit -Entered by user

Writing a program to convert Fahrenheit into Celsius in C

Posted on April 12, 2023April 12, 2023

Table of Contents

  • Writing a program to convert Fahrenheit into Celsius in C
    • Code to Convert Fahrenheit into Celsius
      • Convert Fahrenheit into Celsius  -#1
      • Convert Fahrenheit into Celsius  -Entered by the user-#2
      • Convert Fahrenheit into Celsius  -Using the function-#3
      • Convert Fahrenheit into Celsius Using the function-Entered by the user-#4

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

 

 

Related

Recent Posts

  • Subtract two numbers using method overriding
  • PHP Star triangle Pattern program
  • Using function or method to Write temperature conversion : Fahrenheit into Celsius
  • Function or method:temperature conversion from Fahrenheit into Celsius – Entered by user
  • Write temperature conversion program: Fahrenheit into Celsius
  • How to write a program to convert Fahrenheit into Celsius

tag

Addition (6) Array (38) C++ language (91) C language (98) c sharp (23) Division (6) Function (29) if else (32) Java language (102) JavaScript (5) loops (137) Multiply (7) Oop (2) patterns (65) PHP (13) Python Language (38) Subtraction (7) temperature (20)

Archives

Categories

Address

Global information technology

Puloly south, PointPedro

Jaffna

Srilanka

©2025 Code for Java c | Powered by SuperbThemes