Jump to content

How to Display the Multiplication Table of a Number Using Python, C++, JavaScript, and C - Other Helpful Tutorials - InviteHawk - The #1 Trusted Source for Free Tracker Invites

Buy, Sell, Trade, or Find Free Invites for top private trackers like redacted, blutopia, losslessclub, femdomcult, filelist, Chdbits, Uhdbits, empornium, iptorrents, hdbits, gazellegames, animebytes, privatehd, myspleen, torrentleech, morethantv, bibliotik, alpharatio, blady, passthepopcorn, brokenstones, pornbay, cgpeers, cinemageddon, broadcasthenet, learnbits, torrentseeds, beyondhd, cinemaz, u2.dmhy, Karagarga, PTerclub, Nyaa.si, Polishtracker, and many more.

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


Recommended Posts


  • Member ID:  54,823
  • Followers:  35
  • Topic Count:  3,784
  • Topics Per Day:  2.00
  • Content Count:  11,531
  • Content Per Day:  6.10
  • Reputation:   5,173
  • Achievement Points:  14,768
  • Days Won:  186
  • Joined:  04/24/2021
  • Status:  Offline
  • Last Seen:  

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:

// C++ program to print the multiplication table of a number up to 10 #include <iostream> using namespace std; // Function to print the multiplication table of a number up to 10 void printTable(int num) { for (int i = 1; i <= 10; ++i) { cout << num << " * " << i << " = " << num * i << endl; } } // Driver Code int main() { int num = 5; cout << "Number: " << num << endl; cout << "Multiplication table of " << num << endl; printTable(num); return 0; }

Output:

Number: 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

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:

# Python program to print the multiplication table of a number up to 10 # Function to print the multiplication table of a number up to 10 def printTable(num): for i in range(1, 11): print(num, "*", i, " =", num*i) # Driver Code num = 5 print("Number:", num) print("Multiplication table of", num) printTable(num)

Output:

Number: 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

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:

// JavaScript program to print the multiplication table of a number up to 10 // Function to print the multiplication table of a number up to 10 function printTable(num) { for (let i = 1; i <= 10; ++i) { document.write(num + " * " + i + " = " + num * i + "<br>"); } } // Driver Code var num = 5; document.write("Number: " + num + "<br>"); document.write("Multiplication table of " + num + "<br>"); printTable(num);

Output:

Number: 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

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:

// C program to print the multiplication table of a number up to 10 #include <stdio.h> // Function to print the multiplication table of a number up to 10 void printTable(int num) { for (int i = 1; i <= 10; ++i) { printf("%d * %d = %d \⁠n", num, i, num*i); } } // Driver Code int main() { int num = 5; printf("Number: %d \⁠n", num); printf("Multiplication table of %d \⁠n", num); printTable(num); return 0; }

Output:

Number: 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

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:

// C++ program to print the multiplication table of a number #include <iostream> using namespace std; // Function to print the multiplication table of a number void printTable(int num, int range) { for (int i = 1; i <= range; ++i) { cout << num << " * " << i << " = " << num * i << endl; } } // Driver Code int main() { int num = 5; int range = 14; cout << "Number: " << num << endl; cout << "Range: " << range << endl; cout << "Multiplication table of " << num << endl; printTable(num, range); return 0; }

Output:

Number: 5 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:

# Python program to print the multiplication table of a number # Function to print the multiplication table of a number def printTable(num, r): for i in range(1, r+1): print(num, "*", i, " =", num*i) # Driver Code num = 5 r = 14 print("Number:", num) print("Range:", range) print("Multiplication table of", num) printTable(num, r)

Output:

Number: 5 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:

// JavaScript program to print the multiplication table of a number // Function to print the multiplication table of a number function printTable(num, range) { for (let i = 1; i <= range; ++i) { document.write(num + " * " + i + " = " + num * i + "<br>"); } } // Driver Code var num = 5; var range = 14; document.write("Number: " + num + "<br>"); document.write("Range: " + range + "<br>"); document.write("Multiplication table of " + num + "<br>"); printTable(num, range);

Output:

Number: 5 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:

// C program to print the multiplication table of a number #include <stdio.h> // Function to print the multiplication table of a number void printTable(int num, int range) { for (int i = 1; i <= range; ++i) { printf("%d * %d = %d \⁠n", num, i, num*i); } } // Driver Code int main() { int num = 5; int range = 14; printf("Number: %d \⁠n", num); printf("Range: %d \⁠n", range); printf("Multiplication table of %d \⁠n", num); printTable(num, range); return 0; }

Output:

Number: 5 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.


  • Member ID:  48,211
  • Followers:  60
  • Topic Count:  144
  • Topics Per Day:  0.06
  • Content Count:  30,037
  • Content Per Day:  13.22
  • Reputation:   2,202
  • Achievement Points:  38,169
  • Days Won:  11
  • Joined:  04/09/2020
  • Status:  Offline
  • Last Seen:  

Avoid unnecessary posts such as 'Thank you', 'Welcome', etc. Such posts will be deleted and user will be warned if it happens again. If caught spamming, the following actions are applicable -

  • First time - Warning
  • Second time - 5000 Points will be deducted
  • Third time - Ban for 7 days
  • Fourth time - Permanent Ban

If the post helped you, reward the user by reacting to the post like this -

1.jpg

Guest
This topic is now closed to further replies.
  • Customer Reviews

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.