#include<stdio.h>
main()
{
int i,j,k=1,m,l;
printf("Enter the height of the pyramid");
scanf("%d",&l);
m=0;
for(i=1;i<=l;i++)
{
for(j=2*l-1;j>=i;j--)
{
if(k==0)
{
if((j%2==0) && j<=2*l-m && (j-m)>=i-m)
printf("%c",'*');
else
printf(" ");
}
else if(k==1)
{
if(j%2!=0 && j<=2*l-m && (j-m)>=i-m)
printf("%c",'*');
else
printf(" ");
}
}
printf("\n");
if(k==1)
k=0;
else
k=1;
m=m+1;
}
}
I/O of Program
main()
{
int i,j,k=1,m,l;
printf("Enter the height of the pyramid");
scanf("%d",&l);
m=0;
for(i=1;i<=l;i++)
{
for(j=2*l-1;j>=i;j--)
{
if(k==0)
{
if((j%2==0) && j<=2*l-m && (j-m)>=i-m)
printf("%c",'*');
else
printf(" ");
}
else if(k==1)
{
if(j%2!=0 && j<=2*l-m && (j-m)>=i-m)
printf("%c",'*');
else
printf(" ");
}
}
printf("\n");
if(k==1)
k=0;
else
k=1;
m=m+1;
}
}
I/O of Program
Enter the height of the pyramid 7
* * * * * * *
* * * * * *
* * * * *
* * * *
* * *
* *
*