Skip to content
Menu
Code for Java c
  • Home
  • Java
    • Java Examples
    • Java tutorials
  • C
    • C tutorials
    • C Examples
  • C++
    • C++ Tutorials
    • C++ Examples
  • Python
    • Python Tutorials
    • Python Examples
  • About
    • About me
    • contact us
    • disclaimer
    • Privacy Policy
Code for Java c
Function/method to convert Celsius into Fahrenheit -Entered by user

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

Posted on June 13, 2023

Table of Contents

  • Function/method to convert Celsius into Fahrenheit -Entered by user
    • Code to Celsius into Fahrenheit
      • Convert Celsius into Fahrenheit – Java
      • Convert Celsius into Fahrenheit – C
      • Convert Celsius into Fahrenheit – C++
      • Convert Celsius into Fahrenheit – C#
      • Convert Celsius into Fahrenheit – Python
      • Convert Celsius into Fahrenheit – PHP
      • Convert Celsius into Fahrenheit -JavaScript

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

 

 

Related

Recent Posts

  • Subtract two numbers using method overriding
  • PHP Star triangle Pattern program
  • Using function or method to Write temperature conversion : Fahrenheit into Celsius
  • Function or method:temperature conversion from Fahrenheit into Celsius – Entered by user
  • Write temperature conversion program: Fahrenheit into Celsius
  • How to write a program to convert Fahrenheit into Celsius

tag

Addition (6) Array (38) C++ language (91) C language (98) c sharp (23) Division (6) Function (29) if else (32) Java language (102) JavaScript (5) loops (137) Multiply (7) Oop (2) patterns (65) PHP (13) Python Language (38) Subtraction (7) temperature (20)

Archives

Categories

Address

Global information technology

Puloly south, PointPedro

Jaffna

Srilanka

©2025 Code for Java c | Powered by SuperbThemes