Table of Contents
In this article, we will discuss the concept of Function to divide two numbers
In this post, we are going to learn how to write a program to find division of two numbers using function in PHP language
Program 1
In this program, first the user declare variables as parameter in function. Then when the user call the function, passing the values to variables as argument. finally , the result is calculated and display on the screen
Program 1
<html> <head> <title> Divide two numbers</title> </head> <body> <h3>Division of two number using form</h3> <?php //php script //function definition with parameter function divTwoNumbers($x, $y) { return $x / $y; //calculate the product of two numbers //and return the product of given number } //Calling the function with argument to print result echo "The division of 150 and 3: ".divTwoNumbers(150,3); echo "<br>"; echo "The division of -75 and -15: ".divTwoNumbers(-75,-15); echo "<br>"; echo "The division of 120 and -20: ".divTwoNumbers(120,-20); echo "<br>"; //exit php ?> </body> </html>
When the above code is executed, it produces the following result
Division of two number using form
The division of 150 and 3: 50 The division of -75 and -15: 5 The division of 120 and -20: -6
Program 2
In this program, first the user declare variables as parameter in function. Then when the user call the function, passing the values to variables as argument. finally , the result is calculated and display on the screen
<html> <head> <title> Divide two numbers</title> </head> <body> <h3>Division of two number using form</h3> <?php //php script //function definition with parameter function divTwoNumbers($x, $y) { $div=$x / $y; //calculate division of two numbers //using division(/) operator return $div;//return the result to main echo $div;//print the result when calling the function } //Calling the function and print result echo "The division of 120 and 10: "; echo divTwoNumbers(120,10); echo "<br>"; echo "The division of 250 and -5: "; echo divTwoNumbers(250,-5); echo "<br>"; echo "The division of -180 and -20: "; echo divTwoNumbers(-180,-20); echo "<br>"; //exit php ?> </body> </html>
When the above code is executed, it produces the following result
Division of two number using form
The division of 120 and 10: 12 The division of 250 and -5: -50 The division of -180 and -20: 9
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 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.