calculations

Convert Fahrenheit degrees to Celsius using PHP

Convert Fahrenheit degrees to Celsius using PHP

In this article, we will discuss the concept of the “Convert Fahrenheit degrees to Celsius using PHP”

In this post, we will learn how to write a program to alter Fahrenheit into Celsius.

Here, we have five methods and explain how to calculate Celsius using the given Fahrenheit value and display the result on the screen in PHP programming language.

Code to Alter Fahrenheit into Celsius

Convert Fahrenheit into Celsius  -#1

In this program, the user declares two variables as Celsius and Fahrenheit and initiates the value as 100.0 to Fahrenheit. Then the scientific equation will alter from Fahrenheit into Celsius in the PHP programming language.

Program 1

<?php
//Convert Celsius degrees to Fahrenheit
$fahrenheit=100.0;
//initialize variable
$celsius=(($fahrenheit-32)*5)/9;
//Calculate Fahrenheit
echo("Temperature in Celsius is: ");
$celsius=round($celsius,3);
echo(($celsius));
//print tesult
?>

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

The temperature in Celsius is: 37.778

 

Convert Fahrenheit into Celsius  -Entered by the user-#2

In this program, the user declares two variables as Celsius and Fahrenheit. The program asks for the value from the user to Fahrenheit then the given input will alter from Fahrenheit into Celsius in the PHP programming language using the scientific equation.

Program 2

<?php
//Convert Celsius degrees to Fahrenheit
$fahrenheit=readline("Enter the Fahrenheit: ");
//Ask input rom user
$celsius=(($fahrenheit-32)*5)/9;
//Calculate celsius
echo("The temperature in Celsius is: ");
$celsius=round($celsius,3);
echo(($celsius));
//Print the result
?>

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

Enter the Fahrenheit: 180
The temperature in Celsius is: 82.222

 

Convert Fahrenheit into Celsius  -Using function-#3

In this program, the user declares a double variable as a parameter for Fahrenheit(F) in the user-defined function. When the user runs the program (when calling the function), the value for Fahrenheit passes as an argument to the function.
Finally, the Celsius value is calculated and displayed on the screen using the scientific equation in the PHP programming language.

Program 3

<?php
//Convert Celsius degrees to Celsius using function
function calc_Celsius(int $fahrenheit){
return ($fahrenheit-32) *5/9;
}//user define function to calculate Celsius

echo("The temperature in Celsius is: ");
//$celsius=round($celsius,3);
echo(calc_Celsius(32));
echo "\n";
echo(calc_Celsius(50));
echo "\n";
echo(calc_Celsius(212));
//Calling the function to print result

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

The temperature in Celsius is: 0
10
100

 

Convert Fahrenheit into Celsius Using the function – #4

In this program, the user declares a double variable as a parameter for Fahrenheit(F) in the user-defined function. When the user runs the program (when calling the function), the value of  Fahrenheit passes as an argument to the function.
Finally, the Celsius value is calculated and displayed on the screen using the scientific equation.

Program 4

<?php
//Convert Celsius degrees to Celsius using function
function calc_Celsius(int $fahrenheit){
return ($fahrenheit-32) *5/9;
}//user define function to calculate Celsius
$fahrenheit=98.6;
echo("The temperature in Celsius is: ");
echo(calc_Celsius($fahrenheit));
//Calling the function to print result

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

The temperature in Celsius is: 36.666666666667

 

Convert Fahrenheit into Celsius Using the function-Entered by the user-#5

In this program, the user declares a double variable as a parameter for Fahrenheit(F) in the user-defined function. When the user runs the program (when calling the function), The program asks for the value from the user to Fahrenheit and the value for Fahrenheit passes as an argument to the function.
Finally, the Celsius value is calculated and displayed on the screen using the scientific equation.

Program 5

<?php
//Convert Fahrenheit degrees to Celsius using function
function calc_Celsius(int $fahrenheit){
return ($fahrenheit-32) *5/9;
}//user define function to calculate fahrenheit
$fahrenheit=readline("Enter the Fahrenheit: ");
//Ask input from the user
echo("The temperature in Celsius is: ");
//$fahrenheit=round($celsius,3);
echo(calc_Celsius($fahrenheit));
//Display the output via calling the function

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

Enter the Fahrenheit: 89.0
The temperature in Celsius is: 31.666666666667

 

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

Karmehavannan

Recent Posts

Using function or method to Write temperature conversion : Fahrenheit into Celsius

Using Function or Method to Write to temperature conversion: Fahrenheit into Celsius In this article,…

11 months ago

Function or method:temperature conversion from Fahrenheit into Celsius – Entered by user

Function or method of temperature conversion from Fahrenheit into Celsius In this article, we will…

11 months ago

Write temperature conversion program: Fahrenheit into Celsius

Write temperature conversion program: from Fahrenheit to Celsius In this article, we will discuss the…

11 months ago

How to write a program to convert Fahrenheit into Celsius

How to write a program to convert Fahrenheit into Celsius In this article, we will…

11 months ago

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

Function/method to convert Celsius into Fahrenheit -Entered by user In this article, we will discuss…

11 months ago

Temperature conversion: Celsius into Fahrenheit using function or method

Temperature conversion: Celsius into Fahrenheit using a function or method In this article, we will…

11 months ago

This website uses cookies.