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
PHP program to divide two numbers

PHP program to divide two numbers

Posted on July 23, 2022December 12, 2022

Table of Contents

  • PHP program to divide two numbers
    • Code to the division  of two numbers in PHP
      • Find the division of two numbers  – #1
      • Find the division of two numbers  – #2
      • Find the division of two numbers  using form- #3
      • Find the division of two numbers  using the form- #4

PHP program to divide two numbers

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

Code to the division  of two numbers in PHP

Find the division of two numbers  – #1

Program 1

  • Start HTML tag
  • Start PHP script
  • Declare and initialize two integer variable
  • Calculate the division of given two numbers
  • Display the result on the screen
  • Exit PHP
  • Close HTML tag

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

 

Find the division of two numbers  – #2

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

  • Start HTML tag
  • Start PHP script
  • Declare and initialize two integer variable
  • Calculate the division of given two numbers
  • Assign the result to the third variable
  • Display the result on the screen using the third variable
  • Exit PHP
  • Close HTML tag
<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

 

Find the division of two numbers  using form- #3

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.

  • Create HTML form
  • Exit HTML form
  • Start PHP script
  • Exit PHP

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

PHP program to divide two numbers
Program to divide two numbers

 

Find the division of two numbers  using the form- #4

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.

  • Create HTML form
  • Exit HTML form
  • Start PHP script
  • Exit PHP

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 

 

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