Write a c Programming to create a binary pyramid. - MAKAUT / WBUT MCA 2012 - C Language
1503
Arnab De
08/04/2020
Write a C program to print the above pyramid.
First analysis the pattern,
- each and every line start with 1.
- After printting each time value is inverse.
- Print [Total No. of row - current no of row] space before print any number
- Every row have [(row * 2) - 1] number of column.
void main()
{
int r,c,s,n=4,v=1;
clrscr();
for(r=1;r<=n;r++)
{
for(s=1;s<=n-r;s++)
{
printf(" ");
}
for(c=1;c<=(r*2)-1;c++)
{
printf("%d",v);
v=!v; // NOT Operation on v
// Inverse the value of v
}
printf("\n");
v=1;
}
getch();
}
Output: