Printing Patters in C++ Using For Loops

We will be playing with nested 'for' loops for displaying numbers in different shapes. Such as:

a) 1 2 3 4 5

    1 2 3 4

    1 2 3

    1 2

    1

 

b) 1

     1 2

     1 2 3

     1 2 3 4

     1 2 3 4 5

 

These shapes of numbers can be achieved using nested for loops. You have searched for this topic on your browser because you may need to complete your homework assigned by your college teacher or you are not really a student who is learning to program but spending your spare time in programming in order to gain some problem-solving skills.

But I suggest you solve them by yourselves, as this will improve your ability to think more like a computer when solving computational problems. I am going to list some patterns with their source code. The number of rows and columns will be limited to 5 x 5 in these examples; there’s no furtive behind this limitation, it’s up to you how many rows and columns you want.

Pattern # 01

       Code


Output


Pattern # 02

Code


     Output


Pattern # 03
Code


Output


Pattern # 04

Code


       Output



Pattern # 05
Code


       Output


     Pattern # 06
Code

Output


I hope you have found these examples helpful. I would like to add that there are other possible patterns possible from these codes by making slight tweaks.

Get a pen and a piece of paper and draw different patterns that you can think of. Then use your problem-solving skills to convert the patterns into a code. 

 

 

 

 

 

Comments