Celsius into Fahrenheit
Table of Contents
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
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
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
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
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
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
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
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
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.