Search C Program | nimishsoft@gmail.com

Number Pattern - 39

1234
2341
3421
4321

int main()
{
  int i,j,k;
  for(i=1;i<=4;i++)
  {
    k = i-1;
    for(j=i;j<i+4;j++)
    {
      if(j<=4)
      {
        printf("%d",j);
      }
      else
      {
        printf("%d",k--);
      }
    }
    printf("\n");
  }
  return 0;
}


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


9 comments:

  1. there seems to be a mistake in the logic.Kindly check the pgm once again

    ReplyDelete
    Replies
    1. Thanks for pointing the issue, plz check it now :)

      Delete
    2. it works
      #include
      int main()
      {
      int c;
      int i,j;
      int p=0;
      int l;
      for(i=1;i<=4;i++)
      {
      c = i;
      for(j=1;j<=4-p;j++)
      printf("%d",c++);
      for(j=0;j<p;j++)
      printf("%d",l--);
      p++;
      l = p;
      printf("\n");

      }

      }

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

    ReplyDelete
  3. i am not understand please explain briefly

    ReplyDelete
  4. #include
    void main()
    {
    int i,j;
    i=1;
    while(i<=4)
    {
    j=i;
    while(j<=4)
    {
    printf("%d\t",j);
    j++;
    }
    j=i-1;
    while(j>=1)
    {
    printf("%d\t",j);
    j--;
    }
    printf("\n");
    i++;
    }
    }

    ReplyDelete
  5. Much better logic
    #include
    using namespace std;

    int drawpattern(int *n)
    {
    for (int i=1;i<=*n;i++)
    { int k=i;
    for(int j=1;j<=*n;j++)
    {
    if(k>*n)
    {
    cout<<" "<<(*n+1-j);
    }
    else
    {
    cout<<" "<>n;
    drawpattern(&n);
    return 0;
    }

    ReplyDelete
  6. #include

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

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

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

    for(j=i-1;j>=1;j--)
    {
    printf("%d",j);
    }

    printf("\n");
    }

    return 0;
    }

    ReplyDelete