temperature conversion

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 discuss the title of the “Function/method of temperature conversion from Fahrenheit into Celsius”.

In this post, we will learn how to write a program to convert Fahrenheit into  Celsius  (using the user input)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 to  Fahrenheit into Celsius.
Kelvin is an international unit in temperature measurement.

 

Formula 

F=C x 9/5 + 32

 

Algorithm

  • Declare  variables as double
  • initialize variable
  • Define a user-defined function with a parameter
  • Ask for input from the user
  • Create an object and call the function using the object
  • Print the temperature in Celsius on the screen

 

Code to Fahrenheit into Celsius

Convert Fahrenheit into Celsius- Java

Java language

Program 1

//Java program to Convert Fahrenheit into Celsius
//using method
import java.util.Scanner;
public class Fahrenheit_To_Celsius2
{//method definition
  double fahre_tO_cels(double fahrenheit){
  return ((fahrenheit-32)*5/9);
}

public static void main (String args[]){
    //create object
     Fahrenheit_To_Celsius2 res=new  Fahrenheit_To_Celsius2();
//declaring variables
double fahre; 
Scanner input=new Scanner(System.in);

System.out.print("Enter the value to Fahrenheit: ");
//Ask nput from the user
fahre=input.nextDouble();//Reading the value
double result=res.fahre_tO_cels(fahre);
//Calling the method 
  System.out.print("Temperature in Farhenheit:"+result);
//print the result
}
}

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

Enter the value to Fahrenheit: 98.6
Temperature in Farhenheit:37.0

 

Convert Fahrenheit into Celsius – C

C language

Program 2

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

    return 0;
}

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

Enter temperature in Fahrenheit:98.6
The temperature in Celsius is=37.00

 

Convert Fahrenheit into Celsius- C++

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
  // ask input from the user
    cout<<"Enter the temperature in Fahrenheit:";
  cin>>fahrenheit;//reading the input
    //Calculate fahrenheit
    float celsius=fahrenheitToCelsius(fahrenheit);
  //Calling the function with argument
  
    //display result on the screen
cout<<fahrenheit <<" Fahrenheit"<<" equal to "<<celsius<<" 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

Enter the temperature in Fahrenheit:60
60 Fahrenheit equal to 15.5556 Celsius

 

Convert Fahrenheit into Celsius – C#

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)
    {
        Console.WriteLine ("Enter temperature in Fahrenheit: ");
    //Ask input from the user
    double Fahrenheit=Convert.ToDouble(Console.ReadLine());
    //Reading the input
        double celsius=FahrenheitTocelsius(Fahrenheit);
      //Calling the function with argument
        Console.WriteLine ("The temperature in Celsius: "+celsius);
    //Dispay result on the screen
        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

Enter temperature in Fahrenheit:
212
The temperature in Celsius: 100

 

Convert Fahrenheit into Celsius- Python

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=float(input("Enter temperature in Fahrenheit "))
#Ask input from the user

#Calling the finction
celsius=convertFahreToCels(fahrenheit)
#Display result
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

Enter temperature in Fahrenheit 102.0
102.0 degrees Fahrenheit is equal to 38.9 degree Celsius

 

Convert Fahrenheit into Celsius- PHP

PHP language

Program 6

<?php
//PHP code to Convert Fahrenheit degrees to Celsius 
//using function
function calc_Celsius(int $fahrenheit){
return ($fahrenheit-32) *5/9;
}//user define function to calculate fahrenheit
$fahrenheit=readline("Enter the Fahrenheit: ");
//Ask input from the user
echo("The temperature in Celsius is: ");
//$fahrenheit=round($celsius,3);
echo(calc_Celsius($fahrenheit));
//Display the output via calling the function

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

Enter the Fahrenheit: 50.0
The temperature in Celsius is: 10

 

Convert Fahrenheit into Celsius- JavaScript

JavaScript language

Program 7

//Program to Convert Fahrenheit to  Celsius
function fahreToCels(f){
    return (fahrenheit-32)*5/9;
    //function definition
}
const fahrenheit=prompt("Enter a Fahrenheit value: ");
//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

Enter a Fahrenheit value: 212
212 degrees Fahrenheit is equal to 100 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

Convert Celsius into Fahrenheit in JavaScript

Convert Fahrenheit into Celsius in JavaScript

Karmehavannan

Recent Posts

Multiply two numbers in Java using scanner| 5 different ways

Multiply two numbers in Java using scanner| 5 different ways In this article, we will…

3 months ago

5 different ways to Divide two numbers in Java using scanner

5 Different ways to Divide two numbers in Java using scanner In this article, we…

3 months ago

Learn 8 Ways to Subtract Two Numbers Using Methods in Java

Learn 8 Ways to Subtract Two Numbers Using Methods in Java In this article, we…

4 months ago

10 ways to subtract two numbers in Java

10 ways to subtract two numbers in Java In this article, we will discuss the…

4 months ago

Java Code Examples – Multiply Two Numbers in 5 Easy Ways

Java Code Examples – Multiply Two Numbers in 5 Easy Ways In this article, we…

4 months ago

How to Divide two numbers in Java| 5 different ways

How to Divide two numbers in Java| 5 different ways In this article, we will…

4 months ago

This website uses cookies.