Calculations

Write a function or method to convert C into F -Entered by user

Write a function or method to convert C into F -Entered by the user

In this tutorial, we will discuss the concept of the Write a function or method to convert C into F -Entered by the user

In this post, we will learn how to write a program to convert Celsius into Fahrenheit using the function or method 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. This article discusses how to convert temperature units Celsius into Fahrenheit using different programming languages. 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(c) in the user-defined function/method. When the user calls the function/method, The program asks to enter a value for Cesius and the Celsius value passes to the function/method as an argument through the variable.
Finally, the Fahrenheit value is calculated and displayed using different programming languages’ functions/methods on the screen.

Convert C into F – Java

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 for Celsius
double cels; 
Scanner input=new Scanner(System.in);

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

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

}
}

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

Enter the value to Celsius: 90.0
Temperature in Farhenheit:194.0

 

Convert C into F – C

Program 2

//  function to convert celsius into fahrenheit using C program 
//Entered by user
#include <stdio.h>
float convert_CelsToFahr(float c)
{//Function definition to calculate fahrenheit
    return ((c*9.0/5.0)+32.0);
    
    }
    
int main() {
    // declaring float 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("Tempereture 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:40.0
Tempareture in fahrenheit:
40.00 Celsius= 104.00 Fahrenheit

 

Convert C into F – C++

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

Enter the temperature in celsius:0.0
0 Celsius equal to 32 Fahrenheit

 

Convert C into F – C#

Program 4

// 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)
    {
        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+" 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

Enter temperature in Celsius:
1.00
The temperature in Fahrenheit: 33.8 degrees

 

Convert C into F – Python

Program 5

# 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=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))
#Dispay result on the screen

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

Enter temperature in Celsius 5.0
5.0 degree Celsius is equal to 41.0 degrees Fahrenheit

 

Convert C into F – PHP

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
echo("The temperature in Fahrenheit is: ");
//$celsius=round($celsius,3);
echo(calc_Fahrenheit($celsius));
//Display the output via calling the function

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

Enter the Celsius: 10.0
The temperature in Fahrenheit is: 50

 

 

Convert C into F -JavaScript

Program 7

//Program to Convert Celsius to Fahrenheit 
//Using a user-defined function
function CelsiusTofahrenheit(c){
    //function definition
    return (celsius*1.8)+32
    
}
//Declare and initialize variable
const celsius=50;
//Calling the function to output
var result=CelsiusTofahrenheit(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

50 degrees Celsius is equal to 122 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

 

 

 

 

 

How to write a function or method to convert Celsius into Fahrenheit
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

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

Java program to check odd or even using recursion

Java program to check odd or even using recursion In this tutorial, we discuss a…

2 months ago