Write a c Programming to create a binary pyramid. - WBUT MCA 2012
softetechnologies
08-04-2020    242 times
c Programming binary pyramid WBUT MCA 2012

Write a C program to print the above pyramid.

First analysis the pattern,

  1. each and every line start with 1.
  2. After printting each time value is inverse.
  3. Print [Total No. of row - current no of row] space before print any number
  4. 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:

pyramid Pattern C Programming
softetechnologies
softetechnologies
    Author Details
Arnab De
I have over 16 years of experience working as an IT professional, ranging from teaching at my own institute to being a computer faculty at different leading institute across Kolkata. I also work as a web developer and designer, having worked for renowned companies and brand. Through tutorialathome, I wish to share my years of knowledge with the readers.
    Related Post
  Query About the post