Signup/Sign In

C Program To Print Hollow Pyramid Star Pattern

The Hollow Pyramid Star pattern is similar to the pyramid pattern, The major difference is all the characters inside the pyramid will be replaced by spaces.

Algorithm To Print Hollow Pyramid Star Pattern:

  • Print only one star in the first line
  • In other lines print almost two stars
  • by using the inner loop leave spaces between the stars
  • The no of rows will be multiplied by 2 then subtract the value by 1 and then print in the last row.

C Program To Print Hollow Pyramid Star Pattern:

#include<stdio.h>

int main() {
int i, space, rows, star=0;
printf("Enter The Number Of Rows To Print The Pyramid: \n");
scanf("%d",&rows);

/* Code Block To Print One Row In Every Iteration*/
for(i = 0; i < rows-1; i++) {
/* Printing spaces */
for(space = 1; space < rows-i; space++) {
printf(" ");
}
/* Code Block To Printing stars */
for (star = 0; star <= 2*i; star++) {
if(star==0 || star==2*i)
printf("*");
else
printf(" ");
}
printf("\n");
}
/* Code Block To Print The Last Row */
for(i=0; i<2*rows-1; i++){
printf("*");
}
return 0;
}

Output:

pyramid