Google News
logo
C++ Program to Generate Multiplication Table
Example to generate the multiplication table of a number (entered by the user) using for loop.

* Display Multiplication Table up to 10
* Display Multiplication Table up to a Given Range

Display Multiplication Table up to 10 :

Program :
#include <iostream>
using namespace std;

int main() {

    int n;

    cout << "Enter a positive integer: ";
    cin >> n;

    // run a loop from 1 to 10
    // print the multiplication table
    for (int i = 1; i <= 10; ++i) {
        cout << n << " * " << i << " = " << n * i << endl;
    }
    
    return 0;
}
Output :
Enter a positive integer: 7
7 * 1 = 7
7 * 2 = 14
7 * 3 = 21
7 * 4 = 28
7 * 5 = 35
7 * 6 = 42
7 * 7 = 49
7 * 8 = 56
7 * 9 = 63
7 * 10 = 70
This program above computes the multiplication table up to 10 only.

Display Multiplication Table up to a Given Range :

Program :
#include <iostream>
using namespace std;

int main() {

    int n, range;

    cout << "Enter an integer: ";
    cin >> n;

    cout << "Enter range: ";
    cin >> range;
    
    for (int i = 1; i <= range; ++i) {
        cout << n << " * " << i << " = " << n * i << endl;
    }
    
    return 0;
}
Output :
Enter an integer: 6
Enter range: 14
6 * 1 = 6
6 * 2 = 12
6 * 3 = 18
6 * 4 = 24
6 * 5 = 30
6 * 6 = 36
6 * 7 = 42
6 * 8 = 48
6 * 9 = 54
6 * 10 = 60
6 * 11 = 66
6 * 12 = 72
6 * 13 = 78
6 * 14 = 84