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

Convert Celsius degrees to Fahrenheit using PHP

Posted on May 25, 2023May 25, 2023

Table of Contents

  • Convert Celsius degrees to Fahrenheit using PHP
    • Code to Celsius into Fahrenheit
      • Convert Celsius into Fahrenheit -#1
      • Convert Celsius into Fahrenheit -Entered by the user-#2
      • Convert Celsius into Fahrenheit -Using function-#3
      • Convert Celsius into Fahrenheit Using the function-Entered by the user-#4

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

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