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

Temperature conversion: Celsius into Fahrenheit using function or method

Posted on June 12, 2023

Table of Contents

  • Temperature conversion: Celsius into Fahrenheit using a function or method
    • 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 – JavaScripy

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

 

 

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