#include <stdio.h>
int main() {
int rows;
printf("Enter the number of rows: ");
scanf("%d", &rows);
for (int i = 1; i <= rows; i++) {
for (int j = 1; j <= rows - i; j++) {
printf(" ");
}
for (int j = 1; j <= 2 * i - 1; j++) {
if (i == rows || j == 1 || j == 2 * i - 1) {
printf("*");
} else {
printf(" ");
}
}
printf("\n");
}
return 0;
}
Enter the number of rows: 7
*
* *
* *
* *
* *
* *
*************
rows
to store the number of rows in the hollow star pyramid.printf
and scanf
.fo
r loop to print the hollow star pyramid. The loop runs from 1 to rows
, and each iteration of the loop prints one row of the pyramid.for
loop to print the spaces before the stars. The number of spaces to be printed in each row is equal to rows - i
.for
loop to print the stars and spaces in the row. The number of characters to be printed in each row is equal to 2 * i - 1
.if statement
to check if we are at the first or last row or if we are at the beginning or end of the row, in which case we print a star. Otherwise, we print a space.row
of the pyramid.