Here, we display two Hollow pyramid Patternprograms with coding using nested while loop and also program get input from the user using scanf() function in C language
The user can provide numbers as they wish and get the Hollow pyramid pattern according to their input.
Hollow Pyramid Pattern 1
Hollow Pyramid triangle star pattern
Program 1
#include
#include
int main()
{
int rows;
printf("Enter the number of rows to Pyramid: ");
scanf("%d",&rows);//get input from user for rows
int i,j,k;
i=1;
while(i<=rows){//parent while loop(outer while)
j=i;
while(j
When the above code is executed, it produces the following results
Hollow Pyramid Pattern 2
Inverted Hollow Pyramid triangle star pattern
Program 2
#include
#include
int main()
{
int rows;
printf("Enter the number of rows to Pyramid: ");
scanf("%d",&rows);
int i,j,k;
i=rows;
while(i>=1){//outer for loop
j=rows;
while(j>i){while loop print for space
printf(" ");//print space
j--;
}
k=1;
while(k<2*i){
if(i==rows || (k==1 || k==2*i-1))
printf("*");//print star
else
printf(" ");//print space
k++;
}
i--;
printf("\n");//Move to the next line for print
}
getch();
return 0;
}
When the above code is executed, it produces the following results