C Program to print Hollow Full pyramid star Pattern
Example :-
#include<stdio.h>
int main()
{
int i, space, row, star=0;
printf("Enter The Number ");
scanf("%d",&row);
for(i = 0; i < row-1; i++) {
for(space = 1; space < row-i; space++) {
printf(" ");
}
for (star = 0; star <= 2*i; star++) {
if(star==0 || star==2*i)
printf("*");
else
printf(" ");
}
printf("\n");
}
for(i=0; i<2*row-1; i++){
printf("*");
}
return 0;
}
C Program to Print Hollow Full Pyramid Using Stars Pattern
Explain Program
Step :1
#include <stdio.h>
int main()
{
int i, space, row,
star = 0;
#include <stdio.h> :- printf and scanf.
Step :2
User Input
printf("Enter The Number ");
scanf("%d", &row);
User input how many rows they want for the pyramid.
Step :3
Hollow Pyramid
for(i = 0; i < row - 1; i++) {
for(space = 1;
space < row - i; space++) {
printf("
");
}
if(star == 0
|| star == 2 * i)
printf("*");
else
printf(" ");
}
}
How it work:
- Loop 1) for (i = 0; i < row - 1; i++)
- Controls each row of the hollow pyramid .
- Adds spaces to align the stars in a pyramid shape.
Step :4
for(star = 0; star <= 2*i; star++)
Handle the character in the current row.
Always print * at the start (0) and end (2*i).
Step :5
Bottom Part:
for(i = 0; i < 2 * row - 1; i++) {
printf("*");
}
loop prints a full base of stars at the bottom.
No comments:
Post a Comment