C++ program to print table of any number upto n using the concept of classes. This will take two inputs. First one for number whose table to be printed (For ex: 12) and second is the number upto which table is to be printed (For ex: 17).
CODING:
#include<iostream.h>
#include<conio.h>
class table
{
private:
int num,upto,mul;
public:
table()
{
num=upto=0;
mul=1;
}
table(int n,int u)
{
num=n;
upto=u;
mul=1;
}
void display()
{
for(int i=1; i<=upto; i++)
{
mul=num*i;
cout<<endl<<num<<" * "<<i<<" = "<<mul;
}
}
};
void main()
{
int n,u;
clrscr();
cout<<"Enter any number: ";
cin>>n;
cout<<"Table upto: ";
cin>>u;
table t1(n,u);
t1.display();
getch();
}
Images:
Coding |
Click on images to view them correctly.
Output |
For any query or suggestion please comment below...
Thanks nice post for beginners. Here is another C program to print the multiplication table of N till T terms.
ReplyDelete