Program in C++ to make such a pattern like a pyramid with a number that will repeat the number in the same row.

Write a program in C++ to make such a pattern like a pyramid with a number that will repeat the number in the same row.

Print pyramid pattern using do while loop c++

Flowchart to make such a pattern like a pyramid

Flowchart to make such a pattern like a pyramid program C++ 

C++ Program (Source Code) to make such a pattern like a pyramid

Output

Print pyramid pattern using do while loop c++

Excercise

Find the possible mistakes in the following Shamil’s Flow Table of the Program to make such a pattern like a pyramid with a number that will repeat the number in the same row.

What statement will be executed?
Loop(r)=1, Loop(sp)=1

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

output?

Loop(r)=1, Loop(sp)=2

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

,15,16,17,18, 13,14,15,16,17,18

 

output?

Loop(r)=1, Loop(sp)=3

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

,15,16,17,18,13,14,15,16,17,18, 13,14,15,16,17,18

output?

 

Loop(r)=1, Loop(sp)=4, Loop(disp)=1

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

,15,16,17,18, 13,14,15,16,17,18,

13,14,15,16,17,18

19,20,21,22,23,24,25,26

output?

—1

 

Loop(r)=1, Loop(sp)=4, Loop(disp)=2

1,2,3,4,5,6,7,8,9,10,11,12,(13,14,15,16,17,18,)^3,19,20,21,22,23,24,25,26,27,28,29,30

output?

Move to Next line

 

Loop(r)=2, Loop(sp)=1

1,2,3,4,5,6,7,8,9,10,11,12,(13,14,15,16,17,18)^3,19,20,21,22,23,24,25,26,27,28,29,30,10,11,12,13,14,15,16,17,18

output?

 

Loop(r)=2, Loop(sp)=2,

1,2,3,4,5,6,7,8,9,10,11,12,(13,14,15,16,17,18)^3,19,20,21,22,23,24,25,26,27,28,29,30,10,11,12,13,14,15,16,17,18,10,11,12,13,14,15,16,17,18

output?

 

Loop(r)=2, Loop(sp)=3, Loop(disp)=1

1,2,3,4,5,6,7,8,9,10,11,12,(13,14,15,16,17,18)^3,19,20,21,22,23,24,25, 26,27,28,29,30,(10,11,12,13,14,15,16,17,18)^2,19,20,21,22,23,24,25,26

output?

–2

 

Loop(r)=2, Loop(sp)=3, Loop(disp)=2

1,2,3,4,5,6,7,8,9,10,11,12,(13,14,15,16,17,18)^3,19,20,21,22,23,24,25,26,27,28,29,30,(10,11,12,13,14,15,16,17,18)^2,19,20,21,22

,23,24,25,26,21,22,23,24,25,26

output?

–2-2

Loop(r)=2, Loop(sp)=3, Loop(disp)=3

1,2,3,4,5,6,7,8,9,10,11,12,(13,14,15,16,17,18)^3,19,20,21,22,23,24,25,26,27,28,29,30,(10,11,12,13,14,15,16,17,18)^2,19,20,(21,22,23,24,25,26)^2,27,28,29,

output?

Move to Next line

Loop(r)=3, Loop(sp)=1

1,2,3,4,5,6,7,8,9,10,11,12,(13,14,15,16,17,18)^3,19,20,21,22,23,24,25,26,27,28,29,30,(10,11,12,13,14,15,16,17,18)^2,19,20,(21,22,23,24,25,26)^2,27,28,29,30,10,11,12,13,14,15,16,17,18

output?

 

 

Loop(r)=3, Loop(sp)=2, Loop(disp)=1

1,2,3,4,5,6,7,8,9,10,11,12,(13,14,15,16,17,18)^3,19,20,21,22,23,24,25,26,27,28,29,30(10,11,12,13,14,15,16,17,18)^2,19,20,(21,22,23,24,25,26)^2,27,28,29,30,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26

output?

-3

 

Loop(r)=3, Loop(sp)=2, Loop(disp)=2

1,2,3,4,5,6,7,8,9,10,11,12,(13,14,15,16,17,18)^3,19,20,21,22,23,24,25,26,27,28,29,30(10,11,12,13,14,15,16,17,18)^2,19,20,(21,22,23,24,25,26)^2,27,28,29,30,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,21,22,23,24,25,26

output?

-3-3

 

 

Loop(r)=3, Loop(sp)=2, Loop(disp)=3

1,2,3,4,5,6,7,8,9,10,11,12,(13,14,15,16,17,18)^3,19,20,21,22,23,24,25,26,27,28,29,30,(10,11,12,13,14,15,16,17,18)^2,19,20,(21,22,23,24,25,26)^2,27,28,29,30,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,21,22,23,24,25,26,21,22,23,24,25,26

output?

-3-3-3

 

Loop(r)=3, Loop(sp)=2, Loop(disp)=4

1,2,3,4,5,6,7,8,9,10,11,12,(13,14,15,16,17,18)^3,19,20,21,22,23,24,25,26,27,28,29,30.(10,11,12,13,14,15,16,17,18)^2,19,20,(21,22,23,24,25,26)^2,27,28,29,30,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,21,22,23,24,25,26,21,22,23,24,25,26,27,28,29,30,31

 

 

Latest posts by Prof. Fazal Rehman Shamil (see all)

Buy advertisement space on T4Tutorials

For more details email [email protected]