Solving patterns helps us in understanding looping concepts in any programming language.
With the help of patterns you will be thorough with loops & nested loops.
Note: Before solving any pattern question follow these 4 steps:
- For the outer loop, count the no. of lines i.e rows.
- For the inner loop, focus on the columns & connect them somehow to the rows.
- Print them inside the inner for loop
- Observe symmetry (optional for some patterns)
Pattern - 1
* * * *
* * * *
* * * *
* * * *
Pattern - 2
*
* *
* * *
* * * *
Pattern - 3
1
1 2
1 2 3
Pattern - 4
1
2 2
3 3 3
Pattern - 5
* * * *
* * *
* *
*
Pattern - 6
1 2 3 4 5
1 2 3 4
1 2 3
1 2
1
Pattern - 7
*
***
*****
*******
*********
Pattern - 8
*****
***
*
Pattern - 9
*
***
*****
*****
***
*
Pattern - 10
*
**
***
**
*
Pattern - 11
1
0 1
1 0 1
0 1 0 1
1 0 1 0 1
Pattern - 12
1 1
12 21
123 321
12344321
Pattern - 13
1
2 3
4 5 6
7 8 9 10
Pattern - 14
A
A B
A B C
A B C D
Pattern - 15
A
B B
C C C
D D D D
Pattern - 16
A
B C
D E F
G H I J
Pattern - 17
A B C D
A B C
A B
A
Pattern - 18
A A A A
B B B
C C
D
Pattern - 19
D D D D
C C C
B B
A
Pattern - 20
A
ABA
ABCBA
ABCDCBA
Pattern - 21
E
E D
E D C
E D C B
E D C B A
Pattern - 22
E
D E
C D E
B C D E
A B C D E
Pattern - 23
**********
**** ****
*** ***
** **
* *
* *
** **
*** ***
**** ****
**********
Pattern - 24
* *
** **
*** ***
**** ****
**********
**** ****
*** ***
** **
* *
Pattern - 25
****
* *
* *
****
Pattern - 26
5 5 5 5 5 5 5 5 5
5 4 4 4 4 4 4 4 5
5 4 3 3 3 3 3 4 5
5 4 3 2 2 2 3 4 5
5 4 3 2 1 2 3 4 5
5 4 3 2 2 2 3 4 5
5 4 3 3 3 3 3 4 5
5 4 4 4 4 4 4 4 5
5 5 5 5 5 5 5 5 5