Celsius into Fahrenheit
Table of Contents
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
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
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
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
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
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
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
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
Multiply two numbers in Java using scanner| 5 different ways In this article, we will…
5 Different ways to Divide two numbers in Java using scanner In this article, we…
Learn 8 Ways to Subtract Two Numbers Using Methods in Java In this article, we…
10 ways to subtract two numbers in Java In this article, we will discuss the…
Java Code Examples – Multiply Two Numbers in 5 Easy Ways In this article, we…
How to Divide two numbers in Java| 5 different ways In this article, we will…
This website uses cookies.