Code Scrappers


Binary Number Pyramid Pattern C program


              #include<stdio.h>
              #include<stdlib.h>

              void main()
              {
                  int i, j, flag = 1;

                  for (i = 1; i <= 10; i++)
                  {
                       printf("\n");

                       for (j = 1; j <= i; j++)
                       {
                           printf("%d", flag % 2);

                           flag++;
                       }

                      if (i % 2 == 0)
                      {
                         flag = 1;
                      }

                      else
                      {
                         flag = 0;
                      }
                 }
              }

          



Output

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