Search C Program

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


20 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
  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