Search C Program | nimishsoft@gmail.com

Number Pattern - 15

1
01
101
0101

#include <stdio.h>
int main()
{
  int i, j;
  for(i=1;i<=4;i++)
  {
    for(j=i;j>=1;j--)
    {
      printf("%d",j%2);
    }
    printf("\n");
  }
  return 0;
}



Related Links:
- More Number Pattern Programs
- Star Pattern Programs in C
- Alphabet Pattern Programs in C
- Series Programs in C


25 comments:

  1. I really appreciate your approach

    ReplyDelete
  2. Thank U!!Great job....got stuck here for 10days

    ReplyDelete
  3. this helped me a lot. thank you.

    ReplyDelete
  4. 1
    01
    101
    0101

    #include
    int main()
    {
    int i, j;
    for(i=1;i<=4;i++)
    {
    for(j=i;j>=1;j--)
    {
    printf("%d",j%2);
    }
    printf("\n");
    }
    return 0;
    }

    this program use in (j--) why explain me please

    ReplyDelete
    Replies
    1. Because he wants to print no. Of digits respective to count of rows only

      Delete
    2. It is absolutely WRONG. Don't give such bulshit

      Delete
  5. Check this out (not tested)
    For(i=0;i<4;i++)
    {
    For(j=0;j<i;j++)
    {
    If(i+j%2=0)
    {
    Printf("1");
    }
    Else
    {
    Printf("0");
    }
    }
    Printf("\n");
    }

    ReplyDelete
    Replies
    1. this programe is wrong .......

      Delete
    2. #include
      void main()
      {
      int i,j;
      for(i=1;i<=4;i++)
      {
      for(j=1;j<=4;j++)
      {
      if (i==j)
      printf("1");
      else if (i>j && (i+j)%2 != 0)
      printf("0");
      else if (i>j && (i+j)%2==0)
      printf("1");
      else
      printf(" ");
      }
      printf("\n");
      }
      }

      Delete
    3. Thank you very very much Mr.Anonymous. I've been stuck with this program for weeks & felt very demotivated. This is a cool logic & I'm very thankful to you for posting the right program:).

      Delete
  6. #include

    int main()
    {
    int r,i,j;

    printf("Enter the number of rows : ");
    scanf("%d",&r);

    for(i=1;i<=r;i++)
    {
    for(j=i;j>=1;j--)
    {
    printf("%d",j%2);
    }
    printf("\n");
    }

    return 0;
    }

    ReplyDelete
    Replies
    1. It is the same as the answered posted. Only difference is program is asking a number.

      Delete
  7. #include

    void main()
    {
    for(int i=1;i<=4;i++)
    {
    for(int j=1;j<=i;j++)
    printf("%d",(i+j-1)%2);

    printf("\n");

    }
    }

    ReplyDelete
    Replies
    1. I also thought same .But I did (I+j+1)%2

      Delete
  8. public static void main(String[] arr) {
    // Scanner sc = new Scanner(System.in);
    //System.out.println("Enter anumber to check prime numbers");
    int n = 5;
    int t = n;
    for (int i = 1; i <= n; i++) {
    if (i % 2 != 0) {
    for (int j = 1; j <= i; j++) {
    if (j % 2 != 0) {
    System.out.print(1);
    } else {
    System.out.print(0);
    }
    }
    } else {
    for (int j = 1; j <= i; j++) {
    if (j % 2 != 0) {
    System.out.print(0);
    } else {
    System.out.print(1);
    }
    }
    }
    System.out.println();
    }
    }

    ReplyDelete

  9. #include
    void main()
    {
    int i,j;
    for(i=1;i<=4;i++)
    {
    for(j=1;j<=4;j++)
    {
    if (i==j)
    printf("1");
    else if (i>j && (i+j)%2 != 0)
    printf("0");
    else if (i>j && (i+j)%2==0)
    printf("1");
    else
    printf(" ");
    }
    printf("\n");
    }
    }

    ReplyDelete
  10. #include

    int main()
    {
    int i,j;
    for(i=1;i<=4;i++)
    {

    for(j=1;j<=4;j++)
    {
    if(j==i)
    printf("1");
    if(i-j==2)
    printf("1");
    if(i-j==1)
    printf("0");
    if(j*4==i)
    printf("0");
    }

    printf("\n");
    }
    return 0;
    }
    i got the output but can anyone please tell wheather my code is efficient or not?

    ReplyDelete