C++ Program to print Multiplication table of a given number


In this post, let's learn how to print multiplication table of a given number.

C++ program to generate multiplication table:

#include <iostream>
using namespace std;

int main() 
{
    int num;
    cout << "Enter an integer: " <<endl; 
    cin >> num; //take input from User
    for (int i = 1; i <= 10; i++) { // Iterate for loop for 10 times
        cout << num << " * " <<  i<< " = " << num * i<< endl;
    }
    return 0;
}

Result

Consider you have provided 16 as your input, then below is the output

16 * 1 = 16 
16 * 2 = 32 
16 * 3 = 48 
16 * 4 = 64 
16 * 5 = 80 
16 * 6 = 96 
16 * 7 = 112 
16 * 8 = 128 
16 * 9 = 144 
16 * 10 = 160

If you want to generate the multiplication table to other range like 20, provide i<=20 in the for loop condition which generates the output as below.

16 * 1 = 16 
16 * 2 = 32 
16 * 3 = 48 
16 * 4 = 64 
16 * 5 = 80 
16 * 6 = 96 
16 * 7 = 112 
16 * 8 = 128 
16 * 9 = 144 
16 * 10 = 160 
16 * 11 = 176 
16 * 12 = 192 
16 * 13 = 208 
16 * 14 = 224 
16 * 15 = 240 
16 * 16 = 256 
16 * 17 = 272 
16 * 18 = 288 
16 * 19 = 304 
16 * 20 = 320

You can generate multiplication table in C++ for any other integer here by providing the integer value in the stdin section.