Table of Contents
In this article, we will discuss the title “Using Function or Method to Write temperature conversion: Fahrenheit into Celsius”.
In this post, we will learn how to write a program to convert Fahrenheit into Celsius Using the function and display the result on the screen.
Generally, we are using three temperature units Fahrenheit, Celsius, and Kelvin. Fahrenheit and Celsius are the measuring units in degrees as oF and oC respectively. In this article, we are discussing how to convert temperature units Fahrenheit into Celsius.
Kevin is an international unit in temperature measurement
Formula
F=C x 9/5 + 32
Java language
Program 1
//Java program to Convert Fahrenheit into Celsius //using method import java.util.Scanner; public class Fahrenheit_To_Celsius { static double cels_tO_fahre(double Fahrenheit){ return ((Fahrenheit-32)*5/9); //Calculate celsius value //and return the result to main method } public static void main (String args[]){ Celsius_To_Fahrenheit res=new Celsius_To_Fahrenheit(); Scanner input=new Scanner(System.in); System.out.println("Temperature in Celsius:"+cels_tO_fahre(32.0)); System.out.println("Temperature in Celsius:"+cels_tO_fahre(212.0)); System.out.println("Temperature in Celsius:"+cels_tO_fahre(50.0)); System.out.println("Temperature in Celsius:"+cels_tO_fahre(98.6)); //Dispay result } }
When the above code is executed, it produces the following result
Temperature in Celsius:0.0 Temperature in Celsius:100.0 Temperature in Celsius:10.0 Temperature in Celsius:37.0
C language
Program 2
// program to convert fahrenheit into celsius //using function in C language #include <stdio.h> float convertFahToCels(float fh){ //defined user deined function with parameter return ((fh-32)*5/9); } //Convert fahrenheit into celsius int main() { //Calling function //print celsius float celsius1=convertFahToCels(50.00); float celsius2=convertFahToCels(32.00); float celsius3=convertFahToCels(212.00); float celsius4=convertFahToCels(70.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=10.00 The temperature in Celsius is=0.00 The temperature in Celsius is=100.00 The temperature in Celsius is=21.11 The temperature in Celsius is=98.89
C++ language
Program 3
//C++ program to convert F into C using function #include <iostream> using namespace std; float fahrenheitToCelsius(float); //function prototype int main() { float fahrenheit; //declare float type variables //Calling the function with argument float celsius=fahrenheitToCelsius(00.00); float celsius1=fahrenheitToCelsius(212.00); float celsius2=fahrenheitToCelsius(100.00); float celsius3=fahrenheitToCelsius(98.6); //display result on the screen cout<<celsius <<" Celsius"<<endl; cout<<celsius1 <<" Celsius"<<endl; cout<<celsius2 <<" Celsius"<<endl; cout<<celsius3 <<" Celsius"<<endl; return 0; }//function definition float fahrenheitToCelsius(float fahrenheit){ return ((fahrenheit-32) * 5/9); }
When the above code is executed, it produces the following result
-17.7778 Celsius 100 Celsius 37.7778 Celsius 37 Celsius
C# language
Program 4
// C# program to convert Fahrenheit to Celsius //using function using System; namespace Temperature { public class TempFahreToCels { public static void Main(string[] args) { //Calling the function with argument double celsius=FahrenheitTocelsius(98.6); double celsius1=FahrenheitTocelsius(212); double celsius2=FahrenheitTocelsius(32); double celsius3=FahrenheitTocelsius(00); //Dispay result on the screen Console.WriteLine ("The temperature in Celsius: "+celsius); Console.WriteLine ("The temperature in Celsius: "+celsius1); Console.WriteLine ("The temperature in Celsius: "+celsius2); Console.WriteLine ("The temperature in Celsius: "+celsius3); Console.ReadLine(); } //function definition private static double FahrenheitTocelsius(double fahrenheit) { return (((fahrenheit-32)*5)/9); } } }
When the above code is executed, it produces the following result
The temperature in Celsius: 37 The temperature in Celsius: 100 The temperature in Celsius: 0 The temperature in Celsius: -17.7777777777778
Python language
Program 5
# Python program to convert temperature in Fahrenheit to Celsius #using function def convertFahreToCels(F):#user defined function #Calculate temperature in Celsius C=(F-32)/1.8 return C fahrenheit=70.00 #Declare and initialize variabe #Calling the finction to calculate celsius celsius=convertFahreToCels(fahrenheit) print('%0.1f degrees Fahrenheit is equal to %0.1f degree Celsius ' %(fahrenheit,celsius))
When the above code is executed, it produces the following result
70.0 degrees Fahrenheit is equal to 21.1 degree Celsius
PHP language
Program 6
<?php //PHP code Convert Fahrenheit degrees to Celsius using function function calc_Celsius(float $fahrenheit){ return ($fahrenheit-32) *5/9; }//user define function to calculate Celsius echo("The temperature in Celsius is: "); //$celsius=round($celsius,3); echo(calc_Celsius(212)); echo "\n"; echo(calc_Celsius(32)); echo "\n"; echo(calc_Celsius(98.6)); //Calling the function to print result
When the above code is executed, it produces the following result
The temperature in Celsius is: 100 0 37
JavaScript language
Program 7
//Program to Convert Fahrenheit to Celsius function fahreToCels(f){ return (fahrenheit-32)*5/9; //function definition } const fahrenheit=50.0; //Take input from the user var result=fahreToCels(fahrenheit) //Calling the function //Display the result console.log(`${fahrenheit} degrees Fahrenheit is equal to ${result} degrees Celsius.` );
When the above code is executed, it produces the following result
50 degrees Fahrenheit is equal to 10 degrees Celsius.
Similar post
Celsius into Fahrenheit in the C program
Fahrenheit into Celsius in C program
Celsius into Fahrenheit in C++ program
Fahrenheit into Celsius in C++ program
Celsius into Fahrenheit in the C# program
Fahrenheit into Celsius in C# program
Convert Celsius into Fahrenheit in Python
Convert Fahrenheit into Celsius in Python
Convert Celsius into Fahrenheit in PHP
Convert Fahrenheit into Celsius in PHP
Subtract two numbers using method overriding Program 1
PHP Star triangle Pattern program Here's a simple Java program that demonstrates how to print…
Function or method of temperature conversion from Fahrenheit into Celsius In this article, we will…
Write temperature conversion program: from Fahrenheit to Celsius In this article, we will discuss the…
How to write a program to convert Fahrenheit into Celsius In this article, we will…
Function/method to convert Celsius into Fahrenheit -Entered by user In this article, we will discuss…
This website uses cookies.