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.
/* 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;
}
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 . . .
Comments