To print a hollow pyramid pattern in C, you can use loops. The outer loop controls the rows, and the inner loops manage the spaces and stars to create the hollow effect.
In this example,
#include <stdio.h>
void printHollowPyramid(int rows) {
for (int i = 1; i <= rows; i++) {
for (int j = i; j < rows; j++) {
printf(" ");
}
for (int k = 1; k < (2 * i); k++) {
if (k == 1 || k == (2 * i - 1) || i == rows) {
printf("* ");
} else {
printf(" ");
}
}
printf("\n");
}
}
int main() {
printHollowPyramid(5);
return 0;
}
* * * * * * * * * * * * * * * *
In this tutorial, we learned How to print Hollow Pyramid Pattern in C language with well detailed examples.