How to Display the Multiplication Table of a Number Using Python C++ JavaScript and C

How to Display the Multiplication Table of a Number Using Python C++ JavaScript and C

How to Display the Multiplication Table of a Number Using Python C JavaScript and C

MUO

How to Display the Multiplication Table of a Number Using Python C JavaScript and C

This guide explains how to generate and display multiplication tables using various popular programming languages. When programming using different languages, you can print the multiplication table of a number with few lines of code using loops. But doing this without knowing how to is difficult. Don't worry, though, because we've got you covered. In this article, you'll learn how to print the multiplication table of a number using Python, C++, JavaScript, and C.

Display Multiplication Table of a Number Up to 10

First, let's look at how to display multiplication tables for numbers up to 10.

Problem Statement

You're given a number num. You need to print the multiplication table of num up to 10. Example: Let num = 5. Multiplication table of 5: 5 * 1 = 5
5 * 2 = 10
5 * 3 = 15
5 * 4 = 20
5 * 5 = 25
5 * 6 = 30
5 * 7 = 35
5 * 8 = 40
5 * 9 = 45
5 * 10 = 50

Approach to Display the Multiplication Table of a Number Up to 10

You can follow the approach below to display the multiplication table of a number up to 10: Run a loop from 1 to 10. In each iteration, multiply the given number by iteration no. For example- If the given number is 5, therefore on the 1st iteration, multiply 5 by 1. On the 2nd iteration, multiply 5 by 2, and so on.

C Program to Display the Multiplication Table of a Number Up to 10

Below is the C++ program to display the multiplication table of a number up to 10:
#include iostream
using ;

num)
{
( i = ; i <= ; ++i)
{
cout num * i = num * i endl;
}
}


{
num = ;
cout Number: num endl;
cout Multiplication table of num endl;
printTable(num);
;
} Output: :
Multiplication table of 5
5 * 1 = 5
5 * 2 = 10
5 * 3 = 15
5 * 4 = 20
5 * 5 = 25
5 * 6 = 30
5 * 7 = 35
5 * 8 = 40
5 * 9 = 45
5 * 10 = 50

Python Program to Display the Multiplication Table of a Number Up to 10

Below is the Python program to display the multiplication table of a number up to 10:

:
i range(, ):
print(num, "*", i, " =", num*i)


num =
print("Number:", num)
print("Multiplication table of", num)
printTable(num)
Output: :
Multiplication table of 5
5 * 1 = 5
5 * 2 = 10
5 * 3 = 15
5 * 4 = 20
5 * 5 = 25
5 * 6 = 30
5 * 7 = 35
5 * 8 = 40
5 * 9 = 45
5 * 10 = 50

JavaScript Program to Display the Multiplication Table of a Number Up to 10

Below is the JavaScript program to display the multiplication table of a number up to 10:

() {
( i = ; i <= ; ++i) {
document.write(num + * + i + = + num * i + br);
}
}

num = ;
document.write(Number: + num + br);
document.write(Multiplication table of + num + br);
printTable(num); Output: :
Multiplication table of 5
5 * 1 = 5
5 * 2 = 10
5 * 3 = 15
5 * 4 = 20
5 * 5 = 25
5 * 6 = 30
5 * 7 = 35
5 * 8 = 40
5 * 9 = 45
5 * 10 = 50

C Program to Display the Multiplication Table of a Number Up to 10

Below is the C program to display the multiplication table of a number up to 10:
#include stdio.h

num)
{
( i = ; i <= ; ++i)
{
printf(%d * %d = %d \⁠n, num, i, num*i);
}
}


{
num = ;
printf(Number: %d \⁠n, num);
printf(Multiplication table of %d \⁠n, num);
printTable(num);
;
} Output: :
Multiplication table of 5
5 * 1 = 5
5 * 2 = 10
5 * 3 = 15
5 * 4 = 20
5 * 5 = 25
5 * 6 = 30
5 * 7 = 35
5 * 8 = 40
5 * 9 = 45
5 * 10 = 50

Display Multiplication Table of a Number Up to a Given Range

Of course, you won't necessarily stick to multiplication tables that are 10 and below. It pays to know how to do so for higher ones, too, and you'll find all the information you need below.

Problem Statement

You're given a number num and a range. You need to print the multiplication table of num up to that range. Example: Let num = 5 and range=14. Multiplication table of 5 up to range 14: 5 * 1 = 5
5 * 2 = 10
5 * 3 = 15
5 * 4 = 20
5 * 5 = 25
5 * 6 = 30
5 * 7 = 35
5 * 8 = 40
5 * 9 = 45
5 * 10 = 50
5 * 11 = 55
5 * 12 = 60
5 * 13 = 65
5 * 14 = 70

Approach to Display the Multiplication Table of a Number Up to a Given Range

You can follow the approach below to display the multiplication table of a number up to a given range: Run a loop from 1 to range. In each iteration, multiply the given number by iteration no. For example- If the given number is 5, therefore on the 1st iteration, multiply 5 by 1. On the 2nd iteration, multiply 5 by 2, and so on.

C Program to Display the Multiplication Table of a Number Up to a Given Range

Below is the C++ program to display the multiplication table of a number up to a given range:
#include iostream
using ;

num, range)
{
( i = ; i <= range; ++i)
{
cout num * i = num * i endl;
}
}


{
num = ;
range = ;
cout Number: num endl;
cout Range: range endl;
cout Multiplication table of num endl;
printTable(num, range);
;
} Output: :
Range: 14
Multiplication table of 5
5 * 1 = 5
5 * 2 = 10
5 * 3 = 15
5 * 4 = 20
5 * 5 = 25
5 * 6 = 30
5 * 7 = 35
5 * 8 = 40
5 * 9 = 45
5 * 10 = 50
5 * 11 = 55
5 * 12 = 60
5 * 13 = 65
5 * 14 = 70

Python Program to Display the Multiplication Table of a Number Up to a Given Range

Below is the Python program to display the multiplication table of a number up to a given range:

:
i range(, r+):
print(num, "*", i, " =", num*i)


num =
r =
print("Number:", num)
print("Range:", range)
print("Multiplication table of", num)
printTable(num, r)
Output: :
Range: 14
Multiplication table of 5
5 * 1 = 5
5 * 2 = 10
5 * 3 = 15
5 * 4 = 20
5 * 5 = 25
5 * 6 = 30
5 * 7 = 35
5 * 8 = 40
5 * 9 = 45
5 * 10 = 50
5 * 11 = 55
5 * 12 = 60
5 * 13 = 65
5 * 14 = 70

JavaScript Program to Display the Multiplication Table of a Number Up to a Given Range

Below is the JavaScript program to display the multiplication table of a number up to a given range:

() {
( i = ; i <= range; ++i) {
document.write(num + * + i + = + num * i + br);
}
}

num = ;
range = ;
document.write(Number: + num + br);
document.write(Range: + range + br);
document.write(Multiplication table of + num + br);
printTable(num, range); Output: :
Range: 14
Multiplication table of 5
5 * 1 = 5
5 * 2 = 10
5 * 3 = 15
5 * 4 = 20
5 * 5 = 25
5 * 6 = 30
5 * 7 = 35
5 * 8 = 40
5 * 9 = 45
5 * 10 = 50
5 * 11 = 55
5 * 12 = 60
5 * 13 = 65
5 * 14 = 70

C Program to Display the Multiplication Table of a Number Up to a Given Range

Below is the C program to display the multiplication table of a number up to a given range:
#include stdio.h

num, range)
{
( i = ; i <= range; ++i)
{
printf(%d * %d = %d \⁠n, num, i, num*i);
}
}


{
num = ;
range = ;
printf(Number: %d \⁠n, num);
printf(Range: %d \⁠n, range);
printf(Multiplication table of %d \⁠n, num);
printTable(num, range);
;
} Output: :
Range: 14
Multiplication table of 5
5 * 1 = 5
5 * 2 = 10
5 * 3 = 15
5 * 4 = 20
5 * 5 = 25
5 * 6 = 30
5 * 7 = 35
5 * 8 = 40
5 * 9 = 45
5 * 10 = 50
5 * 11 = 55
5 * 12 = 60
5 * 13 = 65
5 * 14 = 70

Understand Basic Programming Principles to Become a Better Programmer

In this article, you learned how to display the multiplication table of a number in few lines of code using the power of loops. In almost every programming language, you can display the multiplication table in few lines of code. If you want to become a better programmer, you must follow the basic programming principles like KISS (Keep It Simple, Stupid), DRY (Don't Repeat Yourself), Single Responsibility, YAGNI (You Aren't Going to Need It), Open/Closed, Composition Over Inheritance, and so on. We've got guides on these, so why not head over there next?

Share:
0 comments

Comments (0)

Leave a Comment

Minimum 10 characters required

* All fields are required. Comments are moderated before appearing.

No comments yet. Be the first to comment!