In this tutorial, we will write two different pyramid pattern programs using stars in C. Before that, you may go through the following topic in C.
1. Full Pyramid Pattern Program 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 | #include <stdio.h> int main() { int i, space, rows, k = 0; printf("Enter the no. of rows: "); scanf("%d", &rows); for (i = 1; i <= rows; ++i, k = 0) { for (space = 1; space <= rows - i; ++space) printf(" "); while (k != 2 *i - 1) { printf("* "); ++k; } printf("\n"); } return 0; } |
1 2 3 4 5 6 7 | Enter the no. of rows: 6 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * |
2. Inverted full pyramid using * in C
Inverted full Pyramid 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 | #include <stdio.h> int main() { int i, j, rows, gap; printf("Enter the no. of rows: "); scanf("%d", &rows); for (i = rows; i >= 1; --i) { for (gap = 0; gap < rows - i; ++gap) printf(" "); for (j = i; j <= 2 *i - 1; ++j) printf("* "); for (j = 0; j < i - 1; ++j) printf("* "); printf("\n"); } return 0; } |
1 2 3 4 5 6 7 | Enter the no. of rows: 6 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * |