calculations

PHP program to divide two numbers

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

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 

 

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.