Calculations

How to write a function or method to convert Celsius into Fahrenheit

How to write a function or method to convert Celsius into Fahrenheit

In this tutorial, we will discuss the concept of How to write a function or method to convert Celsius into Fahrenheit

In this post, we will learn how to write a program to convert Celsius into Fahrenheit using the function of different programming languages with an Example program.

Temperature and conversion

Conversion equation

Generally, We have known three types of temperature units, Fahrenheit, Celsius, and Kelvin. In this article, we learn How to use different programming languages to convert temperature units Celsius into Fahrenheit. Fahrenheit and Celsius are the measuring units in degrees as 0F and 0C,  respectively.

scientific equation Fahrenheit= Celsius*9/5+32

program to convert Fahrenheit into Celsius

Convert Celsius into Fahrenheit using the function/method

In this program, the user declares a double variable as a parameter for Celsius in the user-defined function. When the user calls the function,  the Celsius value passes to the function as an argument through the variable.
Finally, the Fahrenheit value is calculated and displayed using different programming languages’ functions on the screen.

Program 1

Convert Celsius into Fahrenheit-Java-#1

//Java program 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 using Celsius value
    //and return the result to main method
}
public static void main (String args[]){
    double cels=50,fahre;
// variable declaration and initialize Celsius as 40
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:122.0

 

Convert Celsius into Fahrenheit-Java-#2

Program 2

//Java program to Convert Celsius into Fahrenheit
//using method
 public class Celsius_To_Fahrenheit
{
    static 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[]){
    Celsius_To_Fahrenheit res=new Celsius_To_Fahrenheit();
    //Create object

    System.out.println("Temperature in Celsius:"+cels_tO_fahre(100.0));
    System.out.println("Temperature in Celsius:"+cels_tO_fahre(0.0));
    System.out.println("Temperature in Celsius:"+cels_tO_fahre(40.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:212.0
Temperature in Celsius:32.0
Temperature in Celsius:104.0
Temperature in Celsius:209.48

 

Convert Celsius into Fahrenheit-C-#1

Program 3

//  function to convert celsius into fahrenheit using C program 
//Entered by user
#include <stdio.h>
float convert_CelsToFahr(float c)
{//user defined function 
//Function definition to calculate fahrenheit
    return ((c*9.0/5.0)+32.0);
    
    }
    
int main() {
    float fahrenheit=convert_CelsToFahr(0.00);
    float fahrenheit1=convert_CelsToFahr(100.00);
    float fahrenheit2=convert_CelsToFahr(90.00);
    float fahrenheit3=convert_CelsToFahr(75.00);
    float fahrenheit4=convert_CelsToFahr(50.00);
    //Call the function with argument
     printf("Tempareture in fahrenheit:\n");
    printf("%.2f\n",fahrenheit);
    printf("%.2f\n",fahrenheit1);
    printf("%.2f\n",fahrenheit2);
    printf("%.2f\n",fahrenheit3);
    printf("%.2f",fahrenheit4);
//Dispay result on the screen
    return 0;
}

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

Tempareture in fahrenheit:
32.00
212.00
194.00
167.00
122.00

 

Convert Celsius into Fahrenheit-C-#2

Program 4

// C program to convert celsius  into fahrenheit
//using user defined function
#include <stdio.h>
//user deined function
 float convertCelsToFah(float celsius){
     // function definition
 return (celsius*9/5)+32;
 //Calcuate temparature in fahrenheit
 }
int main() {
    // declaring variables
    float celsius=100,fahrenheit;
    //Convert celsius into fahrenheit
    fahrenheit=convertCelsToFah(celsius);
    printf("The temperature in Fahrenheit is=%.2f ",fahrenheit);

    return 0;
}

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

The temperature in Fahrenheit is=212.00

 

Convert Celsius into Fahrenheit-C++ – #1

Program 5

//C++ code to convert Celsius into Fahrenheit using function
#include <iostream>
using namespace std;
float CelsiusToFahrenheit(float);
//function prototype
int main() {
    float celsius;
    //declare float type variables
    
     float fahrenheit=CelsiusToFahrenheit(100.00);
    float fahrenheit1=CelsiusToFahrenheit(50.00);
   float fahrenheit2=CelsiusToFahrenheit(37.6);
    float fahrenheit3=CelsiusToFahrenheit(00.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 with parameter
float CelsiusToFahrenheit(float celsius){
return (celsius * 9/5)+32;
}//Calculate fahrenheit

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

212 Fahrenheit
122 Fahrenheit
99.68 Fahrenheit
32 Fahrenheit

 

Convert Celsius into Fahrenheit-C++ – #2

Program 6

//C++ program to convert Celsius into Fahrenheit using function
//using initiaized variable
#include <iostream>
using namespace std;
float CelsiusToFahrenheit(float);
//function prototype
int main() {
    float celsius=90.0;
    //declare float type variables
   
    float fahrenheit=CelsiusToFahrenheit(celsius);
  //Calling the function with argument
  //and Assign the resut to fahrenheit
  
    //display result on the screen
cout<<celsius<<" Celsius"<<" equal to "<<fahrenheit <<" Fahrenheit"<<endl;
    return 0;
}
//function definition
float CelsiusToFahrenheit(float celsius){
return (celsius * 9/5)+32;
 //Calculate fahrenheit
}

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

90 Celsius equal to 194 Fahrenheit

 

Convert Celsius into Fahrenheit-C# – #1

Program 7

// 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(36.9);
         double fahrenheit1=celsiusToFahrenheit(00.00);
         double fahrenheit2=celsiusToFahrenheit(100.00);
         
         //Dispay temperature in Fahrenheit on the screen
        Console.WriteLine ("The temperature in Fahrenheit: "+fahrenheit+" Fahrenheit");
        Console.WriteLine ("The temperature in Fahrenheit: "+fahrenheit1+" Fahrenheit");
        Console.WriteLine ("The temperature in Fahrenheit: "+fahrenheit2+" Fahrenheit");
        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.42 Fahrenheit
The temperature in Fahrenheit: 32 Fahrenheit
The temperature in Fahrenheit: 212 Fahrenheit

 

Convert Celsius into Fahrenheit-C# – #2

Program 8

// C# program to convert Celsius to Fahrenheit
//using function Entered by user
using System;
namespace Temperature
{
public class TempCelsToFahre
{
    public static void Main(string[] args)
    {
        double celsius=80.0;
        double fahrenheit=celsiusToFahrenheit(celsius);
        //Calling the function with argument
        //and assign the resut to variable fahrenheit
        Console.WriteLine ("The temperature in Fahrenheit ix "+fahrenheit+" degrees");
        //Dispay result on the screen
        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 is 176 degrees

 

Convert Celsius into Fahrenheit-Python-#1

Program 9

# Python code to convert temperature in Celsius to Fahrenheit
#uaing user defined function
#Entered by user
def convertCelsToFahre(c):#function definition
    #Calculate temperature Fahrenheit
    f=(c*1.8)+32
    return f

celsius=50.0
#Calling the function
fahrenheit=convertCelsToFahre(celsius)
print('%0.1f degree Celsius is equal to %0.1f degrees Fahrenheit ' %(celsius,fahrenheit))
#Dispay result on the screen

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

50.0 degree Celsius is equal to 122.0 degrees Fahrenheit

 

 

Convert Celsius into Fahrenheit-PHP-#1

Program 10

<?php
//Convert Celsius degrees to Fahrenheit using function
function calc_Fahrenheit(int $celsius){
return ($celsius *9/5)+32;
}
//user define function to calculate fahrenheit
echo("The temperature in Fahrenheit is: ");
//$celsius=round($celsius,3);
echo(calc_Fahrenheit(50));
echo "\n";
echo(calc_Fahrenheit(10));
echo "\n";
echo(calc_Fahrenheit(100));
echo "\n";
echo(calc_Fahrenheit(0));
//Calling the function to print result
?>

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

The temperature in Fahrenheit is: 122
50
212
32

Convert Celsius into Fahrenheit-JavaScript-#1

Program 11

//Program 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=60;
//Calling the function to output
var result=CelsTofahre(celsius)

//Display the result
console.log(`${celsius} degrees Celsius is equal to ${result} degrees Fahrenheit.` );

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

60 degrees Celsius is equal to 140 degrees Fahrenheit.

 

Similar post

Code to convert Fahrenheit into Celsius using the Java

Code to convert Celsius into Fahrenheit using the Java

Java program to convert Fahrenheit into Celsius using the method

Java program to convert Celsius into Fahrenheit using the method

 

Code to convert Fahrenheit into Celsius using the C Language

Code to convert Celsius into Fahrenheit using the C Language

C program to convert Fahrenheit into Celsius using the function

C program to convert Celsius into Fahrenheit using the function

 

Code to convert Fahrenheit into Celsius using the C++ Language

Code to convert Celsius into Fahrenheit using the C++ Language

C++ code to convert Fahrenheit into Celsius using the function

C++ code to convert Celsius into Fahrenheit using the function

 

 

 

 

Program for Celsius into Fahrenheit conversion
Write a function or method to convert C into F -Entered by user
Karmehavannan

I am Mr S.Karmehavannan. Founder and CEO of this website. This website specially designed for the programming learners and very especially programming beginners, this website will gradually lead the learners to develop their programming skill.

Recent Posts

How to find reverse number using method in Java

How to find reverse number using method In this article, we will discuss the concept…

20 hours ago

C# inverted full pyramid star pattern

C# inverted full pyramid star pattern In this article, we will discuss the concept of…

3 weeks ago

C# Full Pyramid star pattern program

C# Full Pyramid star pattern program In this article, we will discuss the concept of…

1 month ago

Program to count vowels,consonants,words, characters and space in Java

Program to count vowels, consonants, words, characters and space in Java In this article, we…

1 month ago

How to print multiplication table using Array in C++ language

How to print multiplication table using Array in C++ language In this post, we will…

1 month ago

C Program to multiplication table using Array

C Program to multiplication table using Array In this tutorial , we will discuss about…

2 months ago