R4R
Right Place For Right Person TM
 
R4R C C ExamplesPrint binary triangle Using C
previous

Home

Next

Learn C with example

Print binary triangle Using C

In this example we are going to print binary triangle using C.

We are printing 1 in first line ,0 1 in second line ,1 0 1 in third line ,0 1 0 1 in forth line and so on...

 

 

 

Source Code of Example


/* 1
   0 1
   1 0 1
   0 1 0 1
   1 0 1 0 1 */
   #include<stdio.h>
   #include<conio.h>
   void main()
   {
   int i,j,n;
   clrscr();
   printf("Enter a number\t");
   scanf("%d",&n);
   for(i=1;i<=n;i++)
   {
   for(j=1;j<=i;j++)
   {
   if(i%2==0)
    {
    if(j%2==0)
    printf("1");
    else
    printf("0");
     }
    else
    {
    if(j%2==0)
    printf("0");
    else
    printf("1");
    }
    }
    printf("\n");
    }
    getch();
    }

Output Of Example

Enter a number 5

1
0 1
1 0 1
0 1 0 1
1 0 1 0 1

previous

Home

Next

New Updates

R4R
R4R
R4R
R4R
R4R
R4R
R4R
R4R