;

C Program to Print Half Pyramid Pattern using Binary Number


Tutorialsrack 03/11/2019 C

In this C program, we will learn how to write a program to print half pyramid pattern using binary numbers.

Here is the code of the program to print half pyramid pattern using binary numbers.

Code - C Program to Print Half Pyramid Pattern using Binary Number
/* C program to print following binary half pattern Pyramid:
        0
       01
      010
     0101
    01010
*/

#include<stdio.h>

int main()
{
	int i,j,k,rows;
	printf("Enter The Number of Rows: ");
    scanf("%d",&rows);
	
	for(i=0 ; i<=rows-1 ; i++)
	{
		for(j=rows-1 ; j>i ; j--)
			printf(" ");

		for(k=0 ; k<=i; k++)
		{
			if(k%2==0)
				printf("0");
			else
				printf("1");
		}
		printf("\n");
	}
    
    return 0;
}
Output

Enter The Number of Rows: 6
             0
          01
       010
     0101
  01010
010101

--------------------------------
Process exited after 2.611 seconds with return value 0
Press any key to continue . . .


Related Posts



Comments

Recent Posts
Tags