temperature conversion

Function/method to convert Celsius into Fahrenheit -Entered by user

Function/method to convert Celsius into Fahrenheit -Entered by user

In this article, we will discuss the title of  the “Function/method to convert Celsius into Fahrenheit -Entered by user”

In this post, we will learn how to write a program to convert Celsius into Fahrenheit (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 Celsius. into Fahrenheit.
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
  • Ask for input from the user
  • 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 Convert Celsius into Fahrenheit
//using method
import java.util.Scanner;
 public class Celsius_To_Fahrenheit
{
  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();
// variable declaration
double cels; 
Scanner input=new Scanner(System.in);

System.out.print("Enter the value to Celsius: ");
cels=input.nextDouble();
//Reading the input from user
double result=res.cels_tO_fahre(cels);

  System.out.print("Temperature in Farhenheit:"+result);
//Dispay result
}
}

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

Enter the value to Celsius: 100
Temperature in Farhenheit:212.0

 

Convert Celsius into Fahrenheit – C

C language

Program 2

//  function to convert celsius into fahrenheit using C program 
//Entered by user
#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,fahrenheit;
    //Takes input rom user
     printf("Enter temparature in Celsius :");
    scanf("%f",&celsius);//reading the input
    //Convert celsius to fahrenheit
    fahrenheit=convert_CelsToFahr(celsius);
  //Call the function with argument
   printf("Temperature 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

Enter temperature in celsius:50
Tempareture in fahrenheit:
50.00 Celsius= 122.00 Fahrenheit

 

Convert Celsius into Fahrenheit – C++

C++ language

Program 3

//C++ program to convert Celsius into Fahrenheit using function
//using user input
#include <iostream>
using namespace std;
float CelsiusToFahrenheit(float);
//function prototype
int main() {
    float celsius;
    //declare float type variables
  // ask input from the user
    cout<<"Enter the temperature in celsius:";
  cin>>celsius;//reading the input
   
    float fahrenheit=CelsiusToFahrenheit(celsius);
  //Calling the function with argument
  //and Assign the value 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

Enter the temperature in celsius:100
100 Celsius equal to 212 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 TempCelsToFahre
{
    public static void Main(string[] args)
    {
        Console.WriteLine ("Enter temperature in Celsius: ");
    //Takes input from the user
    double celsius=Convert.ToDouble(Console.ReadLine());
    //Reading the input for Celsius
        double fahrenheit=celsiusToFahrenheit(celsius);
    //Calling the function with argument
    //and assign the resut to variable fahrenheit
        Console.WriteLine ("The temperature in Fahrenheit: "+fahrenheit);
    //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

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

 

Convert Celsius into Fahrenheit – Python

Python language

Program 5

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

celsius=float(input("Enter temperature in Celsius "))
#Reading input from the user

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

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

Enter temperature in Celsius 0
100.0 degree Celsius is equal to 32.0 degrees Fahrenheit

 

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=readline("Enter the celsius: ");
//Ask input from the user
//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

Enter the Celsius: 52
The temperature in Fahrenheit is:125.6

 

Convert Celsius into Fahrenheit -JavaScript

JavaSript 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=prompt("Enter a Celsius value of:: ");
//Calling the function to output
var result=CelsTofahre(celsius)
//Display the result
console.log(`${celsius} degree Celsius is equal to ${result} degrees Fahrenheit .` );

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

Enter a Celsius value of: 20
20 degree Celsius is equal to 68 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

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

11 months 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…

11 months ago

Write temperature conversion program: Fahrenheit into Celsius

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

11 months 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…

11 months ago

Temperature conversion: Celsius into Fahrenheit using function or method

Temperature conversion: Celsius into Fahrenheit using a function or method In this article, we will…

11 months ago

Program to convert Celsius into Fahrenheit-Entered by user

Program to convert Celsius into Fahrenheit-Entered by user In this article, we will discuss the…

11 months ago

This website uses cookies.