C++ Program to Generate Multiplication Table
C++ prgram to generate multiplication table is provided on this page.
This program is exactly similar or the same as c++ program to print multiplication table of 7, so you might want to check that out first.
Multiplication table concept is very simple, but if you don't know it is explained in that article.
The aim of this c++ program is to print the multiplication table of any number. This program accepts a number from user and prints its multiplication table.
C++ program to generate multiplication table
Here is the cpp program to generate multiplication table of any number.
#include <iostream>
using namespace std;
int main()
{
int number;
cout << "Enter any number: ";
cin >> number;
for (int i = 1; i <= 10; ++i) {
cout << number << " * " << i << " = " << number * i << endl;
}
return 0;
}
Output:
Enter any 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
Explanation
Write a for loop from 1 to 10 and calculate the multiplication table with number * i
statement.
Print multiplication table upto Given Range
Here is similar program but the range is custom, it can be up to N, where N is user defined number.
C++ Code to generate multiplication table upto given rangeAccept the range from user, store it into range
variable and then use for loop from 1 to value of range
to print the table upto n.
#include <iostream>
using namespace std;
int main()
{
int number, range;
cout << "Enter any number: ";
cin >> number;
cout << "Enter the range: ";
cin >> range;
for (int i = 1; i <= range; ++i) {
cout << number << " * " << i << " = " << number * i << endl;
}
return 0;
}
Output:
Enter any number: 10 10 * 1 = 10 10 * 2 = 20 10 * 3 = 30 10 * 4 = 40 10 * 5 = 50 10 * 6 = 60 10 * 7 = 70 10 * 8 = 80 10 * 9 = 90 10 * 10 = 100
Comments
Post a Comment