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

Subtract two numbers using method overriding

Subtract two numbers using method overriding   Program 1

3 months ago

PHP Star triangle Pattern program

PHP Star triangle Pattern program Here's a simple Java program that demonstrates how to print…

3 months ago

Using function or method to Write temperature conversion : Fahrenheit into Celsius

Using Function or Method to Write to temperature conversion: Fahrenheit into Celsius In this article,…

1 year ago

Function or method:temperature conversion from Fahrenheit into Celsius – Entered by user

Function or method of temperature conversion from Fahrenheit into Celsius In this article, we will…

1 year ago

Write temperature conversion program: Fahrenheit into Celsius

Write temperature conversion program: from Fahrenheit to Celsius In this article, we will discuss the…

1 year ago

How to write a program to convert Fahrenheit into Celsius

How to write a program to convert Fahrenheit into Celsius In this article, we will…

1 year ago

This website uses cookies.