PHP Program to print the multiplication table

Multiplication Table

In this program, we accept the number from the user and print the multiplication table of that number up to 10. For example, if the inputted number is 5 it will print the multiplication table of 5 up to 10.

How to print the multiplication table using PHP

First, we have to read the input from the user and store it in the variable. And perform the for loop for printing the multiplication for 10 iterations and print the computed result of entered number * 1 to 10.

ALGORITHM

Step 1: Accept the input from the user and store it to the variable num

Step 2: Assign value 1 into variable i and perform the following step until the condition 'i <= 10' becomes false and increment the value of variable i in every iteration

        (i) Print the result of 'num * i' as the multiplication of the entered number

PHP Source Code

                                          <?php

$num = readline("Enter the number: ");

for ($i = 1; $i <= 10; $i++) {
    echo "\t", $num, " * ", $i, " = ", $num * $i, "\n";
}
?>
                                      

OUTPUT

Enter the number: 8
        8 * 1 = 8
        8 * 2 = 16
        8 * 3 = 24
        8 * 4 = 32
        8 * 5 = 40
        8 * 6 = 48
        8 * 7 = 56
        8 * 8 = 64
        8 * 9 = 72
        8 * 10 = 80