Solve these Pattern questions using For Loop and While Loop ( Both ).
Exercise 1: Simple Triangle
Question: Print a right-angled triangle of stars.
Output:
*
**
***
****
*****
Exercise 2: Inverted Triangle
Question: Print an inverted right-angled triangle of stars.
Output:
*****
****
***
**
*
Exercise 3: Diamond Pattern
Question: Print a diamond pattern of stars.
Output:
*
***
*****
*******
*****
***
*
Exercise 4: Hollow Square
Question: Print a hollow square of stars.
Output:
*****
* *
* *
* *
*****
Exercise 5: Pyramid Pattern
Question: Print a pyramid pattern of stars.
Output:
*
***
*****
*******
Exercise 6: Pascal's Triangle
Question: Print Pascal's Triangle.
Output:
1
1 1
1 2 1
1 3 3 1
1 4 6 4 1
Exercise 7: Number Pyramid
Question: Print a number pyramid.
Output:
1
2 3 4
5 6 7 8 9
10 11 12 13 14 15
16 17 18 19 20 21 22
Exercise 8: Hourglass Pattern
Question: Print an hourglass pattern.
Output:
*****
***
*
***
*****
Exercise 9: Checkerboard Pattern
Question: Print a checkerboard pattern/zigzag pattern.
Output:
* * * * *
* * * * *
* * * * *
* * * * *
* * * * *
Exercise 10: Right-Angled Triangle with Numbers
Question: Print a right-angled triangle of numbers, starting from 1 at the top.
Output:
1
2 3
4 5 6
7 8 9 10
11 12 13 14 15