Algorithm
1. Get the number for which the multiplication table is to be displayed from the user.
2. Set the range of the multiplication table (e.g., 1 to 10).
3. Use a loop to iterate through the range.
a. For each iteration, calculate the product of the number and the current iteration value.
b. Display the multiplication expression and the result.
4. End of the program.
Code Examples
#1 Example- Print Multiplication Table in Python
Code -
Python Programming
# Printing table in Python for given number using for loop and function
def print_multiplication_table(number):
print(f"Multiplication table of {number}:")
for i in range(1, 11):
result = number * i
print(f"{number} x {i} = {result}")
# Example usage
num = int(input("Enter a number: "))
print_multiplication_table(num)
Copy The Code &
Try With Live Editor
Output
Multiplication table of 5:
5 x 1 = 5
5 x 2 = 10
5 x 3 = 15
5 x 4 = 20
5 x 5 = 25
5 x 6 = 30
5 x 7 = 35
5 x 8 = 40
5 x 9 = 45
5 x 10 = 50
#2 Example- Multiplication Table in Python Using While Loop
Code -
Python Programming
# How to print multiplication table in Python using while loop and function
def multiplication_table(n):
i = 1
while i <= n:
j = 1
while j <= n:
print(i * j, end='\t')
j += 1
print()
i += 1
# Test the program
number = int(input("Enter a number: "))
multiplication_table(number)
Copy The Code &
Try With Live Editor
Output
1 2 3 4 5 6 7 8 9 10
2 4 6 8 10 12 14 16 18 20
3 6 9 12 15 18 21 24 27 30
4 8 12 16 20 24 28 32 36 40
5 10 15 20 25 30 35 40 45 50
6 12 18 24 30 36 42 48 54 60
7 14 21 28 35 42 49 56 63 70
8 16 24 32 40 48 56 64 72 80
9 18 27 36 45 54 63 72 81 90
10 20 30 40 50 60 70 80 90 100
#3 Example- Multiplication Table in Python Using Lambda Function
Code -
Python Programming
print_multiplication_table = lambda number, rows=10: [print(f"{number} x {i} = {number * i}") for i in range(1, rows + 1)]
# Example usage
num = int(input("Enter a number: "))
print_multiplication_table(num)
Copy The Code &
Try With Live Editor
Output
12 x 1 = 12
12 x 2 = 24
12 x 3 = 36
12 x 4 = 48
12 x 5 = 60
12 x 6 = 72
12 x 7 = 84
12 x 8 = 96
12 x 9 = 108
12 x 10 = 120
Demonstration
Python Programing Example to Display the multiplication Table-DevsEnv