Multiply two numbers using function
Table of Contents
In this article, we will discuss the concept of PHP multiply two numbers using function
In this post, we are going to learn how to write a program to find multiplication 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
<html>
<head>
<title> product of two numbers</title>
</head>
<body>
<h3>Multiply two number using function</h3>
<?php //php script
//function definition with parameter
function mulTwoNumbers($x, $y)
{
return $x * $y;
//calculate the product of two numbers using function
//and return the product of given number
}
//Calling the function with argument to print result
echo "The product of 5 and 12: ".mulTwoNumbers(5,12);
echo "<br>";
echo "The product of 5 and -10: ".mulTwoNumbers(5,-10);
echo "<br>";
echo "The product of -12 and -13: ".mulTwoNumbers(-12,-13);
echo "<br>";
//exit php
?>
</body>
</html> When the above code is executed, it produces the following result
Multiply two number using function
The product of 5 and 12: 60 The product of 5 and -10: -50 The product of -12 and -13: 156
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> product of two numbers</title>
</head>
<body>
<h3>Multiply two number using function</h3>
<?php //php script
//function definition with parameter
function mulTwoNumbers($x, $y)
{
$mul=$x * $y;
//calculate product of two numbers
//using multiplicaion(*) operator
return $mul;//return the result to main
echo $mul;//print the result when calling the function
}
//Calling the function and print result
echo "The product of 15 and 10: ";
echo mulTwoNumbers(15,10);
echo "<br>";
echo "The product of 25 and 10: ";
echo mulTwoNumbers(25,10);
echo "<br>";
echo "The product of 15 and -12: ";
echo mulTwoNumbers(15,-12);
echo "<br>";
//exit php
?>
When the above code is executed, it produces the following result
Multiply two number using function
The product of 15 and 10: 150 The product of 25 and 10: 250 The product of 15 and -12: -180
Similar post
Java program to multiply two numbers
C++ program to multiply two numbers
C program to multiply two numbers
Python program to multiply two numbers
Java program to multiply two floating-point numbers
C++ program to multiply two floating-point numbers
C program to multiply two floating-point numbers
Python program to multiply two floating-point numbers
PHP addition of two numbers using function
Multiply two numbers in Java using scanner| 5 different ways In this article, we will…
5 Different ways to Divide two numbers in Java using scanner In this article, we…
Learn 8 Ways to Subtract Two Numbers Using Methods in Java In this article, we…
10 ways to subtract two numbers in Java In this article, we will discuss the…
Java Code Examples – Multiply Two Numbers in 5 Easy Ways In this article, we…
How to Divide two numbers in Java| 5 different ways In this article, we will…
This website uses cookies.