# C++ Program to Generate multiplication table

January 18, 2023, Learn eTutorial
1277

In this C++ program, we are generating the multiplication table of a user-entered number.

## What is a multiplication table?

A multiplication table is a table of values used to define a multiplication operation in a mathematical system. Multiplication is defined as one of the basic mathematical operation. For 'a' and 'b' are positive integers, 'a*b'  means 'a' is to be added to itself as many times as there are units in 'b'.

For example, 2*3 means 2 is added 3 times itself or 3 is added 2 times itself.
2*3 = 6; 2+2+2 = 6.

A multiplication table of a can be generated by multiplying a with b where the value of b is changed after each step. a * b where b=(1,2,3......................)

## How can we generate a multiplication table using C++?

Here we are generating a C++ program to generate the multiplication table of a user-entered positive integer up to 10 only. So, first read a number n from the user and store the value into an integer type variable n. Here we are using a `for loop` for generating the multiplication table.

Here, we start our multiplication from 1 so initialize i =1; The table computes up to 10 so our condition is i<=10; The value of 'i' is incremented by one in each iteration and updated after each execution of the body of the loop.

### Algorithm

Step 1:  Call the header file` iostream`.

Step 2: Use the `namespace std.`

Step 3: Open the main()

Step 4: Declare integer variable n;

Step 5: Print a message to enter a positive integer.

Step 6: Read the number into the variable n.

Step 7: using a for loop find the product of the number n up to 10

Step 8: print the result.

Step 9: Exit.

## C++ Source Code

```                                          ```#include <iostream>
using namespace std;

int main()
{
int n;

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

for (int i = 1; i <= 10; ++i) {
cout << n << " * " << i << " = " << n * i << endl;
}

return 0;
}```
```

## OUTPUT

```Enter a positive integer: 6
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
```

VIEW ALL
VIEW ALL