C++ Program to Display Multiplication Table
Using for Loop
In the following example, we will create and display the Multiplication Table for the given number (9) using for loop
Example
#include <iostream>
using namespace std;
int main()
{
int table = 9;
int length = 10;
int i = 1;
cout << "Multiplication table: " << table;
for(i=1; i<=length; i++)
cout << "\n" << i << " * " << table << " = " << i * table;
return 0;
}
Output
Multiplication table: 9
1 * 9 = 9
2 * 9 = 18
3 * 9 = 27
4 * 9 = 36
5 * 9 = 45
6 * 9 = 54
7 * 9 = 63
8 * 9 = 72
9 * 9 = 81
10 * 9 = 90
Using while Loop
In the following example, we will create and display the Multiplication Table for the given number (9) using while loop
Example
#include <iostream>
using namespace std;
int main()
{
int table = 9;
int length = 10;
int i = 1;
cout << "Multiplication table: " << table;
while(i <= length)
{
cout << "\n" << i << " * " << table << " = " << i * table;
i++;
}
return 0;
}
Output
Multiplication table: 9
1 * 9 = 9
2 * 9 = 18
3 * 9 = 27
4 * 9 = 36
5 * 9 = 45
6 * 9 = 54
7 * 9 = 63
8 * 9 = 72
9 * 9 = 81
10 * 9 = 90
Using do while Loop
In the following example, we will create and display the Multiplication Table for the given number (9) using do while loop
Example
#include <iostream>
using namespace std;
int main()
{
int table = 9;
int length = 10;
int i = 1;
cout << "Multiplication table: " << table;
do{
cout << "\n" << i << " * " << table << " = " << i * table;
i++;
}while(i <= length);
return 0;
}
Output
Multiplication table: 9
1 * 9 = 9
2 * 9 = 18
3 * 9 = 27
4 * 9 = 36
5 * 9 = 45
6 * 9 = 54
7 * 9 = 63
8 * 9 = 72
9 * 9 = 81
10 * 9 = 90
Display Customized Table
In the following example, we will display the table according to the given table number and table length.
Example
#include <iostream>
using namespace std;
int main()
{
int table, length, i = 1;
cout << "Enter a table number: ";
cin >> table;
cout << "Enter a length: ";
cin >> length;
cout << "\nMultiplication table: " << table;
for(i=1; i<=length; i++)
cout << "\n" << i << " * " << table << " = " << i * table;
return 0;
}
Output
Enter a table number: 5
Enter a length: 10
Multiplication table: 5
1 * 5 = 5
2 * 5 = 10
3 * 5 = 15
4 * 5 = 20
5 * 5 = 25
6 * 5 = 30
7 * 5 = 35
8 * 5 = 40
9 * 5 = 45
10 * 5 = 50
Reminder
Hi Developers, we almost covered 90% of String functions and Interview Question on C++ with examples for quick and easy learning.
We are working to cover every Single Concept in C++.
Please do google search for:
Join Our Channel
Join our telegram channel to get an instant update on depreciation and new features on HTML, CSS, JavaScript, jQuery, Node.js, PHP and Python.
This channel is primarily useful for Full Stack Web Developer.
Share this Page
Meet the Author