Table
The following code shows you how to generate table, two functions are available: first prints the table of the given number and second one generate tables from one number to the other number.
Code
#include "stdafx.h"
#include "iostream"
#include "conio.h"
using namespace std;
void showTableOf(int no)
{
cout << "TABLE OF " << no << " IS : " << endl;
for (int i = 1; i <= 10; i++)
cout<< no << " x " << i << " = " << no * i << endl;
}
void showTableOf(int fromNo , int toNo)
{
for (int i = fromNo; i <= toNo; i++)
{
cout << "TABLE OF " << i << " IS : " << endl;
for (int j = 1; j <= 10; j++)
cout<< i << " x " << j << " = " << i * j << endl;
cout << endl;
}
}
int main()
{
showTableOf(1);cout<<endl;
showTableOf(2);cout<<endl;
showTableOf(3);cout<<endl;
showTableOf(4);cout<<endl;
showTableOf(1,4);cout<<endl;
_getche();
return 0;
}
Output
TABLE OF 1 IS :
1 x 1 = 1
1 x 2 = 2
1 x 3 = 3
1 x 4 = 4
1 x 5 = 5
1 x 6 = 6
1 x 7 = 7
1 x 8 = 8
1 x 9 = 9
1 x 10 = 10
TABLE OF 2 IS :
2 x 1 = 2
2 x 2 = 4
2 x 3 = 6
2 x 4 = 8
2 x 5 = 10
2 x 6 = 12
2 x 7 = 14
2 x 8 = 16
2 x 9 = 18
2 x 10 = 20
TABLE OF 3 IS :
3 x 1 = 3
3 x 2 = 6
3 x 3 = 9
3 x 4 = 12
3 x 5 = 15
3 x 6 = 18
3 x 7 = 21
3 x 8 = 24
3 x 9 = 27
3 x 10 = 30
TABLE OF 4 IS :
4 x 1 = 4
4 x 2 = 8
4 x 3 = 12
4 x 4 = 16
4 x 5 = 20
4 x 6 = 24
4 x 7 = 28
4 x 8 = 32
4 x 9 = 36
4 x 10 = 40
TABLE OF 1 IS :
1 x 1 = 1
1 x 2 = 2
1 x 3 = 3
1 x 4 = 4
1 x 5 = 5
1 x 6 = 6
1 x 7 = 7
1 x 8 = 8
1 x 9 = 9
1 x 10 = 10
TABLE OF 2 IS :
2 x 1 = 2
2 x 2 = 4
2 x 3 = 6
2 x 4 = 8
2 x 5 = 10
2 x 6 = 12
2 x 7 = 14
2 x 8 = 16
2 x 9 = 18
2 x 10 = 20
TABLE OF 3 IS :
3 x 1 = 3
3 x 2 = 6
3 x 3 = 9
3 x 4 = 12
3 x 5 = 15
3 x 6 = 18
3 x 7 = 21
3 x 8 = 24
3 x 9 = 27
3 x 10 = 30
TABLE OF 4 IS :
4 x 1 = 4
4 x 2 = 8
4 x 3 = 12
4 x 4 = 16
4 x 5 = 20
4 x 6 = 24
4 x 7 = 28
4 x 8 = 32
4 x 9 = 36
4 x 10 = 40
0 comments:
Post a Comment