C++ program to print multiplication table of a number. - coderforcoders

Search

Wednesday, 13 March 2019

C++ program to print multiplication table of a number.

#include<iostream>
using namespace std;
class mathTable{
public:
int num,i;
void printTable()
{
cout<<" The multiplication table of "<<num<<" is"<<endl;
for(i=1;i<=10;i++)
cout<<num<<" * "<<i<<" = "<<num*i<<endl;
}
};
int main()
{
mathTable obj1;
cout<<"Please enter a number\n";
cin>>obj1.num;
obj1.printTable();
cout<<endl;
return 0;
}

Output 1:
Please enter a number
10
The multiplication table of 10 is
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

Output 2:
Please enter a number
65
The multiplication table of 65 is
65 * 1 = 65
65 * 2 = 130
65 * 3 = 195
65 * 4 = 260
65 * 5 = 325
65 * 6 = 390
65 * 7 = 455
65 * 8 = 520
65 * 9 = 585
65 * 10 = 650


No comments:

Post a Comment