Print half pyramids using * as shown
Pattern 1 :
* ** *** **** *****
Logic :
i | height | Number of * (= i) |
---|---|---|
1 | 5 | 1 |
2 | 5 | 2 |
3 | 5 | 3 |
4 | 5 | 4 |
5 | 5 | 5 |
Solution :
Pattern 2 :
* ** *** **** *****
Logic :
i | height | Number of spaces (= height - i) | Number of * (= i) |
---|---|---|---|
1 | 5 | 4 | 1 |
2 | 5 | 3 | 2 |
3 | 5 | 2 | 3 |
4 | 5 | 1 | 4 |
5 | 5 | 0 | 5 |
Solution :
Pattern 3 :
***** **** *** ** *
Logic :
i | height | Number of * (= height - i + 1) |
---|---|---|
1 | 5 | 5 |
2 | 5 | 4 |
3 | 5 | 3 |
4 | 5 | 2 |
5 | 5 | 1 |
Solution :
Pattern 4 :
***** **** *** ** *
Logic :
i | height | Number of spaces (= i - 1) | Number of * (= height - i + 1) |
---|---|---|---|
1 | 5 | 0 | 5 |
2 | 5 | 1 | 4 |
3 | 5 | 2 | 3 |
4 | 5 | 3 | 2 |
5 | 5 | 4 | 1 |