Function

Temperature conversion: Celsius into Fahrenheit using function or method

Temperature conversion: Celsius into Fahrenheit using a function or method

In this article, we will discuss the title of  the “Temperature conversion: Celsius into Fahrenheit using a function or method”

In this post, we will learn how to write a program to convert Celsius into Fahrenheit 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

 

Algorithm

  • Declare  variables as double
  • initialize variable as cels=40
  • Define a user-defined function
  • Create an object and call the function
  • Print the temperature in Fahrenheit on the screen

 

Code to Celsius into Fahrenheit

Convert Celsius into Fahrenheit – Java

Java language

Program 1

//Java program to Solution to Convert Celsius into Fahrenheit
//using method
public class Celsius_To_Fahrenheit
{//function definition
  double cels_tO_fahre(double celsius){
  return (celsius*9/5)+32;
  //Calculate Fahrenheit value 
  //and return the result to main method
}
public static void main (String args[]){
  double cels=40,fahre;
// variable declaration 
Celsius_To_Fahrenheit res = new Celsius_To_Fahrenheit();
//Create object
double result=res.cels_tO_fahre(cels);
  System.out.println("Temperature in Farhenheit:"+result);
  

}
}

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

Temperature in Farhenheit:104.0

 

Convert Celsius into Fahrenheit – C

C  Language

Program 2

//  function to convert celsius into fahrenheit using C program
#include <stdio.h>
float convert_CelsToFahr(float c)
{//function definition
  return ((c*9.0/5.0)+32.0);
  
  }
int main() {
    // declaring loat type variables
    float celsius=100,fahrenheit;

    //Convert celsius to fahrenheit
    fahrenheit=convert_CelsToFahr(celsius);
  //Call the function with argument
   printf("Tempareture in fahrenheit:\n");
    printf("%.2f Celsius= %.2f Fahrenheit ",celsius,fahrenheit);
//Dispay result on the screen
    return 0;
}

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

Tempareture in fahrenheit:
100.00 Celsius= 212.00 Fahrenheit

 

 

Convert Celsius into Fahrenheit – C++

C++  Language

Program 3

//C++ code to convert C into F using function
#include <iostream>
using namespace std;
float CelsiusToFahrenheit(float);
//function prototype with parameter
int main() {
    float celsius;
    //declare float type variables
    //Calculate fahrenheit
    float fahrenheit=CelsiusToFahrenheit(105.00);
    float fahrenheit1=CelsiusToFahrenheit(100.00);
    float fahrenheit2=CelsiusToFahrenheit(32.50);
    float fahrenheit3=CelsiusToFahrenheit(37.00);
  //Calling the function with argument
  
    //display result on the screen
  
cout<<fahrenheit <<" Fahrenheit"<<endl;
cout<<fahrenheit1 <<" Fahrenheit"<<endl;
cout<<fahrenheit2 <<" Fahrenheit"<<endl;
cout<<fahrenheit3 <<" Fahrenheit"<<endl;
    return 0;
}
//function definition
float CelsiusToFahrenheit(float celsius){
return (celsius * 9/5)+32;
}

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

221 Fahrenheit
212 Fahrenheit
90.5 Fahrenheit
98.6 Fahrenheit

 

Convert Celsius into Fahrenheit – C#

C#  Language

Program 4

// C# program to convert Celsius to Fahrenheit
//using function
using System;
namespace Temperature
{
public class TempCelsToFahre1
{
    public static void Main(string[] args)
    {
    //Calling the function with argument
        double fahrenheit=celsiusToFahrenheit(37.00);
         double fahrenheit1=celsiusToFahrenheit(100.00);
         double fahrenheit2=celsiusToFahrenheit(10.00);
     
     //Dispay temperature in Fahrenheit on the screen
        Console.WriteLine ("The temperature in Fahrenheit: "+fahrenheit);
        Console.WriteLine ("The temperature in Fahrenheit: "+fahrenheit1);
        Console.WriteLine ("The temperature in Fahrenheit: "+fahrenheit2);
        Console.ReadLine();
    }
  //function definition
  private static double celsiusToFahrenheit(double celsius)
  {
  return ((celsius*9/5)+32);
}
}
}

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

The temperature in Fahrenheit: 98.6
The temperature in Fahrenheit: 212
The temperature in Fahrenheit: 50

 

Convert Celsius into Fahrenheit – 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=52.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

52.0 degrees Fahrenheit is equal to 11.1 degree Celsius

 

Convert Celsius into Fahrenheit – PHP

PHP  Language

Program 6

<?php
//Convert Celsius degrees to Fahrenheit using function
function calc_Fahrenheit(int $celsius){
return ($celsius *9/5)+32;
}//user define function to calculate fahrenheit
$celsius=10;
//Declare and initialize variable
echo("The temperature in Fahrenheit is:" );
//Take input rom the user
echo(calc_Fahrenheit($celsius));
//Calling the function to display result
?>

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

The temperature in Fahrenheit is:50

 

Convert Celsius into Fahrenheit – JavaScripy

JavaScript  Language

Program 7

//Code to Convert Celsius to Fahrenheit 
//Using a user-defined function
function CelsTofahre(c){
  //function definition
    return (celsius*1.8)+32
    
}
//Declare and initialize variable
const celsius=10
//Calling the function to output
var result=CelsTofahre(celsius)
//Display the result
console.log(`${celsius} degree Celsius is equal to ${result} degree Fahrenheit .` );

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

10 degree Celsius is equal to 50 degrees Fahrenheit.

 

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

Subtract two numbers using method overriding

Subtract two numbers using method overriding   Program 1

3 months ago

PHP Star triangle Pattern program

PHP Star triangle Pattern program Here's a simple Java program that demonstrates how to print…

3 months ago

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,…

1 year 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…

1 year ago

Write temperature conversion program: Fahrenheit into Celsius

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

1 year 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…

1 year ago

This website uses cookies.