In this tutorial, we will discuss the concept of PHP program to divide two numbers using function
In this topic, we are going to learn how to write a program to division of two numbers using user-defined function in PHP programming language
In this program, the user declare two integer variables $x and $y as parameters of the user defined function. Then two numbers are divided using division(/) operator. finally when the user call the function with passing argument, the result is displayed on the screen
Program 1
<?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 15 and 3: ".divTwoNumbers(15,3); echo "<br>"; echo "The division of -75 and -5: ".divTwoNumbers(-75,-5); echo "<br>"; echo "The division of 120 and -30: ".divTwoNumbers(120,-30); echo "<br>"; //exit php ?>
When the above code is executed, it produces the following result
The product of 15 and 3: 5 The product of -75 and -5: 15 The product of 120 and -30: -4
In this program, the user declare two integer variables $x and $y as parameters of the user defined function. Then two numbers are divided using division(/) operator. finally when the user call the function with passing argument, the result is displayed on the screen
Program 2
<?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 150 and 10: "; echo divTwoNumbers(150,10); echo "<br>"; echo "The division of 25 and -5: "; echo divTwoNumbers(25,-5); echo "<br>"; echo "The division of -180 and -12: "; echo divTwoNumbers(-180,-12); echo "<br>"; //exit php ?>
When the above code is executed, it produces the following result
The division of 150 and 10: 15 The division of 25 and -5: -5 The division of -180 and -12: 15
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
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…
Java program to check odd or even using recursion In this tutorial, we discuss a…