In this tutorial, we will discuss the concept of PHP dividing two numbers
In this topic, we are going to learn how to write a program to divide two numbers in PHP programming language
In this program, the user declare and initialize two integer variables $x and $y. Then two numbers are divided using division(/) operator. finally the result is displayed on the screen
Program 1
<?php //php script $num1=300; $num2=15; $div=$num1/$num2; echo "Division of given numbers: $num1/$num2=".$div; //exit php ?>
When the above code is executed, it produces the following result
Division of given numbers: 300/15=20
In this program, the user asked to enter two numbers(by passing input value to form). Then two numbers are divided using / operator and then the result is displayed on the screen
program 2
<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']; $mul=$number1 / $number2; echo "The division of $number1 and $number2 is: ".$mul; } ?>
When the above code is executed, it produces the following result
In this program, the user asked to enter two numbers(by passing input value to form). Then two numbers are divided using / operator and then the result is displayed on the screen
program 3
<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; } ?>
When the above code is executed, it produces the following result
Similar post
Java program to divide two numbers
C program to divide two numbers
C++ program to divide two numbers
Python program to divide two numbers
Java program to divide two floating-point numbers
C program to divide two floating-point numbers
How to find reverse number using method In this article, we will discuss the concept…
C# inverted full pyramid star pattern In this article, we will discuss the concept of…
C# Full Pyramid star pattern program In this article, we will discuss the concept of…
Program to count vowels, consonants, words, characters and space in Java In this article, we…
How to print multiplication table using Array in C++ language In this post, we will…
C Program to multiplication table using Array In this tutorial , we will discuss about…