Site icon T4Tutorials.com

C++ Multiplication table Vertically from 1 to n

Write a program in C++ to display the multiplication table vertically from 1 to n.

Flowchart of Multiplication table in C++

C++ Source Code of Program of Multiplication table Vertically from 1 to n

#include<iostream>
using namespace std;
int main()
{
	int i,j,a,b;
	cout<<"Enter two numbers: ";
	cin>>a>>b;
	i=a;
	do
	{
		j=1;
		do
		{
			cout<<i<<"*"<<j<<"="<<i*j<<endl;
			j++;
		}
		while(j<=10);
		i++;
	}
	while(i<=b);
}

Output

 

Exercise

Find the possible mistakes in the following Shamil’s Flow Table of the program of  Multiplication Table vertically from 1 to 2.

Loop

a=1,  b=2

Condition What line will execute Actual work to do
j=1<=10

 

1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16, 17 j=1

i*j=1,  j++,  j=2

j=2<=10

 

True 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,

17,12,13,14,15,16,17

1*2=2

j++, j=3

j=3<=10 True 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,

17,12,13,14,15,16,17, 12,13,14,15,16,17

1*3=3

j++, j=4

j=4<=10 True 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,

17,12,13,14,15,16,17, 12,13,14,15,16,

17, 12,13,14,15,16, 17

1*4=4

j++, j=5

j=5<=10 True 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,

17,12,13,14,15,16,17, 12,13,14,15,16,

17, 12,13,14,15,16, 17, 12,13,14,15,16, 17

1*5=5

j++, j=6

j=6<=10 True 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,

17,12,13,14,15,16,17, 12,13,14,15,16,

17, 12,13,14,15,16, 17, 12,13,14,15,16

, 17, 12,13,14,15,16, 17

1*6=6

j++, j=7

j=7<=10 True 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,

17,12,13,14,15,16,17, 12,13,14,15,16,

17, 12,13,14,15,16, 17, 12,13,14,15,16

, 17, 12,13,14,15,16,17,12,13,14,15,16, 17

1*7=7

j++, j=8

j=8<=10 True 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,

17,12,13,14,15,16,17, 12,13,14,15,16,

17, 12,13,14,15,16, 17, 12,13,14,15,16

, 17, 12,13,14,15,16,17,12,13,14,15,16

,17,12,13,14,15,16, 17

1*8=8

j++, j=9

j=9<=10 True 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,

17,12,13,14,15,16,17, 12,13,14,15,16,

17, 12,13,14,15,16, 17, 12,13,14,15,16

, 17, 12,13,14,15,16,17,12,13,14,15,16

,17,12,13,14,15,16,17,12,13,14,15,16, 17

1*9=9

j++, j=10

j=10<=10 True 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,

17,12,13,14,15,16,17, 12,13,14,15,16,

17, 12,13,14,15,16, 17, 12,13,14,15,16

, 17, 12,13,14,15,16,17,12,13,14,15,16

,17,12,13,14,15,16,17,12,13,14,15,16

,17,12,13,14,15,16, 17

1*10=10

j++, j=11

j=11<=10 False 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,

17,12,13,14,15,16,17, 12,13,14,15,16,

17, 12,13,14,15,16, 17, 12,13,14,15,16

, 17, 12,13,14,15,16,17,12,13,14,15,16

,17,12,13,14,15,16,17,12,13,14,15,16

,17,12,13,14,15,16,17,18,19, 20

i++,  i=2
 

i<=b, b=2

1<=2

 

True

 

1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,

17,12,13,14,15,16,17, 12,13,14,15,16,

17, 12,13,14,15,16, 17, 12,13,14,15,16

, 17, 12,13,14,15,16,17,12,13,14,15,16

,17,12,13,14,15,16,17,12,13,14,15,16

,17,12,13,14,15,16,17,18,19,20,9, ,10,11,12,13,14,15,16

 

j=1

i*j=2*1=2

j++,  j=2

j<=10

j=2<=10

True 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,

17,12,13,14,15,16,17, 12,13,14,15,16,

17, 12,13,14,15,16, 17, 12,13,14,15,16

, 17, 12,13,14,15,16,17,12,13,14,15,16

,17,12,13,14,15,16,17,12,13,14,15,16

,17,12,13,14,15,16,17,18,19,20,9, ,10,11,12,13,14,15,16,17,12,13,14,15,16,

j=1

i*j=2*2=4

j++,  j=3

j=3<=10 True 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,

17,12,13,14,15,16,17, 12,13,14,15,16,

17, 12,13,14,15,16, 17, 12,13,14,15,16

, 17, 12,13,14,15,16,17,12,13,14,15,16

,17,12,13,14,15,16,17,12,13,14,15,16

,17,12,13,14,15,16,17,18,19,20,9, ,10,11,12,13,14,15,16,17,12,13,14,15,16,

,17,12,13,14,15,16

j=1

i*j=2*3=6

j++,  j=4

j=4<=10 True 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,

17,12,13,14,15,16,17, 12,13,14,15,16,

17, 12,13,14,15,16, 17, 12,13,14,15,16

, 17, 12,13,14,15,16,17,12,13,14,15,16

,17,12,13,14,15,16,17,12,13,14,15,16

,17,12,13,14,15,16,17,18,19,20,9, ,10,11,12,13,14,15,16,17,12,13,14,15,16,

,17,12,13,14,15,16,17,12,13,14,15,16

j=1

i*j=2*4=8

j++,  j=5

j=5<=10 True 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,

17,12,13,14,15,16,17, 12,13,14,15,16,

17, 12,13,14,15,16, 17, 12,13,14,15,16

, 17, 12,13,14,15,16,17,12,13,14,15,16

,17,12,13,14,15,16,17,12,13,14,15,16

,17,12,13,14,15,16,17,18,19,20,9, ,10,11,12,13,14,15,16,17,12,13,14,15,16,

,17,12,13,14,15,16,17,12,13,14,15,16, 17,12,13,14,15,16

j=1

i*j=2*5=10

j++,  j=6

j=6<=10 True 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,

17,12,13,14,15,16,17, 12,13,14,15,16,

17, 12,13,14,15,16, 17, 12,13,14,15,16

, 17, 12,13,14,15,16,17,12,13,14,15,16

,17,12,13,14,15,16,17,12,13,14,15,16

,17,12,13,14,15,16,17,18,19,20,9, ,10,11,12,13,14,15,16,17,12,13,14,15,16,

,17,12,13,14,15,16,17,12,13,14,15,16, 17,12,13,14,15,16, 17,12,13,14,15,16

j=1

i*j=2*6=12

j++,  j=7

j=7<=10 True 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,

17,12,13,14,15,16,17, 12,13,14,15,16,

17, 12,13,14,15,16, 17, 12,13,14,15,16

, 17, 12,13,14,15,16,17,12,13,14,15,16

,17,12,13,14,15,16,17,12,13,14,15,16

,17,12,13,14,15,16,17,18,19,20,9, ,10,11,12,13,14,15,16,17,12,13,14,15,16,

,17,12,13,14,15,16,17,12,13,14,15,16, 17,12,13,14,15,16, 17,12,13,14,15,16

, 17,12,13,14,15,16

j=1

i*j=2*7=14

j++,  j=8

j=8<=10 True 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,

17,12,13,14,15,16,17, 12,13,14,15,16,

17, 12,13,14,15,16, 17, 12,13,14,15,16

, 17, 12,13,14,15,16,17,12,13,14,15,16

,17,12,13,14,15,16,17,12,13,14,15,16

,17,12,13,14,15,16,17,18,19,20,9, ,10,11,12,13,14,15,16,17,12,13,14,15,16,

,17,12,13,14,15,16,17,12,13,14,15,16, 17,12,13,14,15,16, 17,12,13,14,15,16

, 17,12,13,14,15,16, 17,12,13,14,15,16

j=1

i*j=2*8=16

j++,  j=9

j=9<=10 True 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,

17,12,13,14,15,16,17, 12,13,14,15,16,

17, 12,13,14,15,16, 17, 12,13,14,15,16

, 17, 12,13,14,15,16,17,12,13,14,15,16

,17,12,13,14,15,16,17,12,13,14,15,16

,17,12,13,14,15,16,17,18,19,20,9, ,10,11,12,13,14,15,16,17,12,13,14,15,16,

,17,12,13,14,15,16,17,12,13,14,15,16, 17,12,13,14,15,16, 17,12,13,14,15,16

, 17,12,13,14,15,16, 17,12,13,14,15,16

, 17,12,13,14,15,16

j=1

i*j=2*9=18

j++,  j=10

j=10<=10 True 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,

17,12,13,14,15,16,17, 12,13,14,15,16,

17, 12,13,14,15,16, 17, 12,13,14,15,16

, 17, 12,13,14,15,16,17,12,13,14,15,16

,17,12,13,14,15,16,17,12,13,14,15,16

,17,12,13,14,15,16,17,18,19,20,9, ,10,11,12,13,14,15,16,17,12,13,14,15,16,

,17,12,13,14,15,16,17,12,13,14,15,16, 17,12,13,14,15,16, 17,12,13,14,15,16

, 17,12,13,14,15,16, 17,12,13,14,15,16

, 17,12,13,14,15,16

j=1

i*j=2*10=20

j++,  j=11

 

 

 

 

j=11<=10

 

 

 

 

 

 

 

False

 

 

 

 

1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,

17,12,13,14,15,16,17, 12,13,14,15,16,

17, 12,13,14,15,16, 17, 12,13,14,15,16

, 17, 12,13,14,15,16,17,12,13,14,15,16

,17,12,13,14,15,16,17,12,13,14,15,16

,17,12,13,14,15,16,17,18,19,20,9, ,10,11,12,13,14,15,16,17,12,13,14,15,16,

,17,12,13,14,15,16,17,12,13,14,15,16, 17,12,13,14,15,16, 17,12,13,14,15,16

, 17,12,13,14,15,16, 17,12,13,14,15,16

, 17,12,13,14,15,16,17,

 

 

 

 

i++

i=3

i<=b

i=3<=2

 

 

False 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,

17,12,13,14,15,16,17, 12,13,14,15,16,

17, 12,13,14,15,16, 17, 12,13,14,15,16

, 17, 12,13,14,15,16,17,12,13,14,15,16

,17,12,13,14,15,16,17,12,13,14,15,16

,17,12,13,14,15,16,17,18,19,20,9, ,10,11,12,13,14,15,16,17,12,13,14,15,16,

,17,12,13,14,15,16,17,12,13,14,15,16, 17,12,13,14,15,16, 17,12,13,14,15,16

, 17,12,13,14,15,16, 17,12,13,14,15,16

, 17,12,13,14,15,16,17,18,19,20,21

End

Flowchart of Multiplication table Vertically from 1 to n using for loop

C++ Source Code of Program of Multiplication table Vertically from 1 to n using for loop

Lets us see the Program of Multiplication table showing Vertically from 1 to n by using for loop.

#include<iostream>
using namespace std;
int main()
{
	int j,i,n;
	cout<<"Input upto the table number starting from 1 : ";
	cin>>n;
	cout<<"Multiplication table from 1 to "<<n<<endl;
	for(i=1;i<=10;i++)
	{
		for(j=1;j<=n;j++)
		{
			if(j<=n-1)
			{
				cout<<i<<" X "<<j<<" = "<<j*i;
			}
			else
			{
				cout<<i<<" X "<<j<<" = "<<j*i;
			}
		}
		cout<<endl;
	}
}

Output

 

Declarations Flow table (DFT) of Multiplication table Vertically from 1 to n

Let us see the DFT of the above program.

Variable Declaration

(Line Number)

Initialization

(Line Number)

Use

(Line Number)

I 5 9A,9C 9B,19,15
j 5 11A,11C, 11B,13,15,19
n 5 7 9B,13

Flowchart of first 10 natural numbers using while loop

Sum of the 1st ten natural numbers in C++ using while loop

#include <iostream>
using namespace std;
int main()
{
    int  j, sum = 0;
    cout<<"The first 10 natural number is :\n";
    j=1;
    while(j<=10)
    {
    	sum = sum + j;
        cout<<" "<<j;    
        j++;
    }
    cout<<"\nThe Sum is : "<< sum;
}

Output

The first 10 natural number is :

1 2 3 4 5 6 7 8 9 10

The Sum is : 55

 

Exit mobile version