C++ Program to Generate Multiplication Table

In this post, we will learn how to generate a multiplication table using C++ Programming language.

A Multiplication table is a table that shows the product of two numbers. We will be writing a program which will generate a multiplication table for any positive integer entered by the user.

So, without further ado, let’s begin this tutorial.

C++ Program to Generate Multiplication Table

// C++ Program to Generate Multiplication Table
#include <iostream>
using namespace std;

int main(){
    int num;
    
    // Asking for input
    cout << "Enter a positive number: ";
    cin >> num;
    
    // Multiplication table
    for (int i = 1; i <= 10; ++i){
        cout << num << " * " << i << " = " << num * i << endl;
    }
    return 0;
}

Output

Enter a positive number: 13
13 * 1 = 13
13 * 2 = 26
13 * 3 = 39
13 * 4 = 52
13 * 5 = 65
13 * 6 = 78
13 * 7 = 91
13 * 8 = 104
13 * 9 = 117
13 * 10 = 130

How Does This Program Work ?

    int num;

In this program, we have declared an int data type variable named num.

    // Asking for input
    cout << "Enter a positive number: ";
    cin >> num;

Then, the user is asked to enter a positive integer. The value of this integer will get stored in the num named variable.

    // Multiplication table
    for (int i = 1; i <= 10; ++i){
        cout << num << " * " << i << " = " << num * i << endl;
    }

We have used a for loop function to generate the multiplication table.

Conclusion

I hope after going through this post, you understand how to generate a multiplication table using C++ Programming language.

If you have any doubt regarding the program, feel free to contact us in the comment section. We will be delighted to assist you to solve your query.

Also Read:

Leave a Comment

Your email address will not be published. Required fields are marked *