Multiplication of two numbers:
Table of Contents
In this article, we will discuss the concept of PHP multiplication of two numbers
In this post, we are going to learn how to write a program to find product of two numbers in PHP language
Program 1
In this program, the user initialize the values to variables and calculates the product of the given numbers using multiplication(*) operator. And then the result is displayed on the screen.
Program 1
<html> <head> <title> Multiplication of two numbers</title> </head> <body> <h3>Multiply two number using form</h3> <?php //php script $num1=25; $num2=12; $mul=$num1*$num2; echo "product: ".$mul; //exit php ?> </body> </html>
When the above code is executed, it produces the following result
Multiply two number using form
product: 300
In this program, the user initiates the values to variables and calculates the product of the given numbers using multiplication(*) operator. then the result is assigned to another variable ($res) and the the result is displayed on the screen using that variable
Program 2
<html> <head> <title> Multiplication of two numbers</title> </head> <body> <h3>Multiply two number using form</h3> <?php //php script $num1=5; $num2=15;//declare variables $mul=$num1*$num2;//calculate product of two numbers $res="Product: ".$mul; //the output asigned to third variable echo $res;//print the result on the screen //exit php ?> </body> </html>
When the above code is executed, it produces the following result
Multiply two number using form
Product: 75
In this program, the user is entered the values to variables using form(the program Asks input from the user to form) and calculates the product of the given numbers using multiplication(*) operator and the result is assigned to third variable ($mul) .finally the result is displayed on the screen using third variable.
program 3
<html>
<head>
<title> Multiplication of two numbers</title>
</head>
<body>
<h3>Multiply 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="multiply"/><br>
</form>
<?php
if(isset($_POST['submit']))
{
$number1=$_POST['number1'];
$number2=$_POST['number2'];
$mul=$number1 * $number2;
echo "The multiplication of $number1 and $number2 is: ".$mul;
}
?>
</body>
</html> When the above code is executed, it produces the following result
In this program, the user is entered the values to variables using form(the program Asks input from the user to form) and calculates the product of the given numbers using multiplication(*) operator and the result is assigned to third variable ($mul) .finally the result is displayed on the screen using third variable.
program 4
<html>
<head>
<title> Multiplication of two numbers</title>
</head>
<body>
<h3>Multiply 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="multiply"/><br>
</form>
<?php
if(isset($_GET['num1']) && isset ($_GET['num1'])){
$num1=intval($_GET['num1']);
$num2=intval($_GET['num2']);
echo "The multiplication of $num1 and $num2 is: ";
echo $num1*$num2;
}
?> When the above code is executed, it produces the following result
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
PHP subtraction of two numbers
PHP subtraction 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.