C++ program to Print Table of any Number

The concept of generating table of any number is multiply particular number from 1 to 10.
num * 1 
num * 2 
num * 3 
num * 4 
num * 5 
num * 6 
num * 7 
num * 8 
num * 9 
num * 10

Example

#include<iostream.h>
#include<conio.h>

void main()
{
int i,no,table=1;
clrscr();
cout<<"Enter any num : ";
cin>>no;
clrscr();
cout<<"Table of "<<no;
for(i=1;i< =10;i++)
{
table=no*i;
cout<<" \n"<<table;
cout<<"\n";
}
getch();
}

Output

Enter any num : 5
Table of 5
5
10
15
20
25
30
35
40
45
50
Explanation of Program

Code

for(i=1;i< =10;i++)
{
table=no*i;
cout<<" \n"<<table;
cout<<"\n";
}
In the above Code execute for loop from 1 to 10, and given number is multiply by 1 and next iteration number is multiply by 2 and at third iteration number is multiply by 3,........10. and there results are print on screen

Table using while loop

#include<iostream.h>
#include<conio.h>

void main()
{
int a=1,no,table=1;
clrscr();
cout<<"Enter any num: ";
cin>>no;
while(a< =10)
{
table=a*no;
cout<<table;
cout<<"\n";
a++;
}
getch();
}

Output

Enter any num: 2
Table
2
4
6
8
10
12
14
16
18
20

0 comments: