Arithmetic Caculation

PHP multiplication of two numbers: PHP program

PHP multiplication of two numbers: PHP program

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

Code to product  of two numbers in PHP

Find product of two numbers  – #1

Program 1

  • Start HTML tag
  • Start PHP script
  • Declare and initialize two integer variable
  • Calculate product of given two numbers
  • Display result on the screen
  • Exit PHP
  • Close HTML tag

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

 

Find product of two numbers  – #2

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

  • Start HTML tag
  • Start PHP script
  • Declare and initialize two integer variable
  • Calculate product of given two numbers
  • Assign the result to third variable
  • Display result on the screen
  • Exit PHP
  • Close HTML tag
<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

 

Find product of two numbers  using form- #3

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.

  • Create HTML form
  • Exit HTML form
  • Start PHP script
  • Exit PHP

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

 

 

Find product of two numbers  using form- #4

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.

  • Create HTML form
  • Exit HTML form
  • Start PHP script
  • Exit PHP

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

Multiplication of two numbers

 

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

PHP addition of two numbers using function

PHP subtraction of two numbers

PHP subtraction of two numbers using function

 

Karmehavannan

Recent Posts

Multiply two numbers in Java using scanner| 5 different ways

Multiply two numbers in Java using scanner| 5 different ways In this article, we will…

3 months ago

5 different ways to Divide two numbers in Java using scanner

5 Different ways to Divide two numbers in Java using scanner In this article, we…

3 months ago

Learn 8 Ways to Subtract Two Numbers Using Methods in Java

Learn 8 Ways to Subtract Two Numbers Using Methods in Java In this article, we…

4 months ago

10 ways to subtract two numbers in Java

10 ways to subtract two numbers in Java In this article, we will discuss the…

4 months ago

Java Code Examples – Multiply Two Numbers in 5 Easy Ways

Java Code Examples – Multiply Two Numbers in 5 Easy Ways In this article, we…

4 months ago

How to Divide two numbers in Java| 5 different ways

How to Divide two numbers in Java| 5 different ways In this article, we will…

4 months ago

This website uses cookies.