Table of Contents
In this article, we will discuss the concept of a PHP program to divide two numbers
In this post, we are going to learn how to write a program to calculate the division of two numbers in the PHP language
Program 1
In this program, the user declares and initializes the values to variables and calculates the division of the given numbers using the division(/) operator. And then the result is displayed on the screen.
Program 1
<html> <head> <title> Division of two numbers</title> </head> <body> <h3>Division of two number using form</h3> <?php //php script $n1=30; $n2=3; $div=$n1/$n2; echo "Division of given numbers: $n1/$n2=".$div; //exit php ?> </body> </html>
When the above code is executed, it produces the following result
Division of two numbers using the form
Division of given numbers: 30/3=10
In this program, the user declares and initiates the values to variables and calculates the division of the given numbers using the division(/) operator. then the result is assigned to a third variable ($res) and the result is displayed on the screen using the third variable
Program 2
<html> <head> <title> Division of two numbers</title> </head> <body> <h3>Division of two number using form</h3> <?php //php script $n1=40; $n2=8; $div=$n1/$n2; $res="Division of given numbers: $n1/$n2=".$div; echo $res; //exit php ?> </body> </html>
When the above code is executed, it produces the following result
Division of two numbers using the form
Division of given numbers: 40/8=5
In this program, the user enters the values to variables using the form(the program Asks input from the user to form) and calculates the division of the given numbers using the division(/) operator and the result is assigned to a third variable ($div) . Finally, the result is displayed on the screen using the third variable.
program 3
<html> <head> <title> Divide two numbers</title> </head> <body> <h3>Division of two number using form</h3> <form method = "post"> Enter 1st number <input type = "number" name="number1"/><br><br> Enter 2nd number <input type = "number" name="number2"/><br><br> <input type = "submit" name="submit" value="Division"/><br> </form> <?php if(isset($_POST['submit'])) { $number1=$_POST['number1']; $number2=$_POST['number2']; $div=$number1 / $number2; echo "The division of $number1 and $number2 is: ".$div; } ?> </body> </html>
When the above code is executed, it produces the following result
In this program, the user enters the values of variables using the form(the program Asks input from the user to form) and calculates the division of the given numbers using the division(/) operator. Finally, the result is displayed on the screen using the echo function.
Program 4
<html> <head> <title> Divide two numbers</title> </head> <body> <h3>Division of two number using form</h3> <form> Enter 1st number <input type = "number" name="num1"/><br><br> Enter 2nd number <input type = "number" name="num2"/><br><br> <input type = "submit" name="submit" value="division"/><br> </form> <?php if(isset($_GET['num1']) && isset ($_GET['num1'])){ $num1=intval($_GET['num1']); $num2=intval($_GET['num2']); echo "The division of $num1 and $num2 is: "; echo $num1/$num2; } ?> </body> </html>
When the above code is executed, it produces the following result
Suggested post
Java program to divide two number
C program to divide two number
C++ program to divide two number
Python program to divide two number
java program to find the quotient and remainder
C program to find quotient and remainder
C++ program to find quotient and remainder
Python program to find quotient and remainder
Subtract two numbers using method overriding Program 1
PHP Star triangle Pattern program Here's a simple Java program that demonstrates how to print…
Using Function or Method to Write to temperature conversion: Fahrenheit into Celsius In this article,…
Function or method of temperature conversion from Fahrenheit into Celsius In this article, we will…
Write temperature conversion program: from Fahrenheit to Celsius In this article, we will discuss the…
How to write a program to convert Fahrenheit into Celsius In this article, we will…
This website uses cookies.