In this tutorial, we will write a C program to print a hollow triangle star pattern. Before that, you may go through the following topics in C.
Hollow Triangle Pattern in C
Hollow equilateral triangle pattern in C.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 | #include <stdio.h> int main() { int i, j, k, rows; printf("Enter the no. of rows: "); scanf("%d", &rows); for (i = 1; i <= rows; i++) { for (j = i; j < rows; j++) { printf(" "); } for (k = 1; k <= (2 *i - 1); k++) { if (k == 1 || i == rows || k == (2 *i - 1)) printf("*"); else printf(" "); } printf("\n"); } return 0; } |
Output: