temperature conversion

Convert Celsius degrees to Fahrenheit using PHP

Convert Celsius degrees to Fahrenheit using PHP

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

In this post, we will learn how to write a program to alter Celsius into Fahrenheit and display the result on the screen in PHP language. Here, we have five methods and explain how to calculate Fahrenheit using the given Celsius value and display the result on the screen in the PHP programming language

Code to Celsius into Fahrenheit

Convert Celsius into Fahrenheit -#1

In this program, the user declares two variables as Celsius and Fahrenheit, and initiates the value as 50.0 to the variable- Celsius. The scientific equation will convert it from Celsius into Fahrenheit in the PHP programming language.

Program 1

<?php
//php code to convert Celsius to Fahrenheit
$celsius=50.0;
//declare and initilize variable
$fahrenheit=(($celsius*9)/5)+32;
//Calculate Fahrenheit
echo("The temperature in Fahrenheit is: ");
echo(($fahrenheit));
//Print the result
?>

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

The temperature in Fahrenheit is: 122

 

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

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

Program 2

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

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

Enter the Celsius: 100.00
The temperature in Fahrenheit is: 212

 

Convert Celsius into Fahrenheit -Using function-#3

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

Program 3

<?php
function calc_Fahrenheit(int $celsius){
return ($celsius *9/5)+32;
}
//user define function to calculate fahrenheit
echo("The temperature in Fahrenheit is: ");
//$celsius=round($celsius,3);
echo(calc_Fahrenheit(90));
echo "\n";
echo(calc_Fahrenheit(10));
echo "\n";
echo(calc_Fahrenheit(100));
//Calling the function to print result

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

The temperature in Fahrenheit is: 194
50
212

 

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

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

Program 4

<?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=17;
//Declare and initialize variable
echo("The temperature in Fahrenheit is: ");
//$celsius=round($celsius,3);
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: 62.6

 

Program 5

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

<?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
echo("The temperature in Fahrenheit is: ");
//$celsius=round($celsius,3);
echo(calc_Fahrenheit($celsius));
//Display the output via calling the function

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

Enter the Celsius: 40.0
The temperature in Fahrenheit is: 104

 

 

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

Subtract two numbers using method overriding

Subtract two numbers using method overriding   Program 1

3 months ago

PHP Star triangle Pattern program

PHP Star triangle Pattern program Here's a simple Java program that demonstrates how to print…

3 months ago

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,…

1 year 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…

1 year ago

Write temperature conversion program: Fahrenheit into Celsius

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

1 year 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…

1 year ago

This website uses cookies.