Search C Program | nimishsoft@gmail.com

Number Pattern - 57

      1
    2   2
  3       3
4           4
  3       3
    2   2
      1

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


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



12 comments:

  1. #include

    int main()
    {
    int l,n,i,j,k=1,sp,p=3;
    printf("Enter the number of line:\n");
    scanf("%d",&n);
    sp=n;
    for(i=0;i<2*n-1;i++)
    {
    for(j=0;j<=sp;j++)
    {
    printf(" ");
    }
    printf("%d",k);
    if(i>0 && i<2*n-2)
    {
    for(l=0;l0)
    p+=4;
    }
    else
    {
    sp+=2;
    k--;
    p-=4;
    }
    printf("\n");
    }
    }

    ReplyDelete
  2. Replies
    1. /******************************************************************************

      Online C++ Compiler.
      Code, Compile, Run and Debug C++ program online.
      Write your code in this editor and press "Run" button to compile and execute it.

      *******************************************************************************/

      #include

      using namespace std;

      int main()
      {
      int i,j,n,k;
      cin>>n;
      for(i=1;i<=n;i++)
      {
      for(k=1;k<=n-i;k++)
      {
      cout<<" ";
      }
      for(j=1;j<=2*i-1;j++)
      {
      if(j==1||j==2*i-1)
      {
      cout<=1;j--)
      {
      cout<=1;i--)
      {
      for(k=1;k<=n-i;k++)
      {
      cout<<" ";
      }
      for(j=1;j<=2*i-1;j++)
      {
      if(j==1||j==2*i-1)
      {
      cout<<i;
      }
      else
      {
      cout<<" ";
      }
      }
      cout<<endl;
      }

      return 0;
      }

      Delete
  3. Below code will be easy to understand for beginners.....

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

    for(j=2;j<=4;j++)
    if(j==i)
    printf("%d",j);
    else
    printf(" ");

    printf("\n");
    }

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

    for(j=2;j<=4;j++)
    if(j==i)
    printf("%d",j);
    else
    printf(" ");

    printf("\n");
    }
    printf("\n");
    }

    ReplyDelete
  4. #include
    using namespace std;
    int main()
    {
    int n;
    cin>>n;
    int size=2*n-1;
    int mid=(size-1)/2;
    int x=1;
    for(int i=0;i<size;i++)
    {
    if(i==mid)
    printf("%d",x++);
    else
    {
    cout<<" ";
    }
    }
    cout<<endl;
    int p=mid-1,q=mid+1;
    int flag=0;
    for(int i=0;i<size-2;i++)
    {
    for(int j=0;j<size;j++)
    {
    if(p==j||q==j)
    printf("%d",x);
    else
    cout<<" ";
    }
    if(p==0)
    {
    flag=1;
    }
    if(flag==1)
    {
    p++;
    q--;
    x--;
    }
    else
    {
    p--;
    q++;
    x++;
    }
    cout<<endl;
    }
    for(int i=0;i<size;i++)
    {
    if(i==mid)
    printf("1");
    else
    {
    cout<<" ";
    }
    }
    }

    ReplyDelete
  5. I NEED CODE FOR
    1
    2 3
    4 5 6
    7 8 9 10
    4 5 6
    2 3
    1

    ReplyDelete
    Replies
    1. #include
      int main()
      {
      int n,i,j,k;
      scanf("%d",&n);
      for(i=1;i<=n;i++)
      {
      for(j=1;j<=n-i;j++)
      {
      printf(" ");
      }
      printf("%d",i);
      for(k=0;k<=2*(i-2);k++)
      {
      printf(" ");
      }
      if(i>1)
      {
      printf("%d",i);
      }
      printf("\n");
      }
      for(i=n-1;i>0;i--)
      {
      for(j=1;j<=n-i;j++)
      {
      printf(" ");
      }
      printf("%d",i);
      for(k=0;k<=2*(i-2);k++)
      {
      printf(" ");
      }
      if(i>1)
      {
      printf("%d",i);
      }
      printf("\n");
      }
      return 1;
      }

      Delete
  6. #include
    int main()
    {
    int n,i,j,k;
    scanf("%d",&n);
    for(i=1;i<=n;i++)
    {
    for(j=1;j<=n-i;j++)
    {
    printf(" ");
    }
    printf("%d",i);
    for(k=0;k<=2*(i-2);k++)
    {
    printf(" ");
    }
    if(i>1)
    {
    printf("%d",i);
    }
    printf("\n");
    }
    for(i=n-1;i>0;i--)
    {
    for(j=1;j<=n-i;j++)
    {
    printf(" ");
    }
    printf("%d",i);
    for(k=0;k<=2*(i-2);k++)
    {
    printf(" ");
    }
    if(i>1)
    {
    printf("%d",i);
    }
    printf("\n");
    }
    return 1;
    }

    ReplyDelete
  7. #include
    main() {
    int i,j;
    for(i=1; i<=4; i++)
    {
    for(j=3; j>=i; j--) {
    printf(" "); }
    for(j=i; j>=1; j--)
    { if(j>=i)
    printf("%d",i);
    else
    printf("");}
    for(j=i*2-1;j>1;j--)
    { if(j-1>1)
    printf(" ");
    else
    printf("%d",i);
    }printf("\n");}
    for(i=3;i>=1;i--)
    {
    for(j=3;j>=i;j--)
    printf(" ");
    for(j=i;j>=1;j--)
    { if(j>=i)
    printf("%d",i);
    else
    printf(" ");
    }
    for(j=i-1;j>=1;j--)
    {
    if(j>1)
    printf(" ");
    else
    printf("%d",i);
    }
    printf("\n");
    }
    }

    ReplyDelete
  8. i need a code of

    A
    B B
    C C
    D D
    E E
    D D
    C C
    B B
    A

    ReplyDelete
  9. #include
    int main()
    {
    int n,i,j,k;
    scanf("%d",&n);
    for(i=1;i<=n;i++)
    {
    for(j=1;j<=n-i;j++)
    {
    printf(" ");
    }
    printf("%d",i);
    for(k=0;k<=2*(i-2);k++)
    {
    printf(" ");
    }
    if(i>1)
    {
    printf("%d",i);
    }
    printf("\n");
    }
    for(i=n-1;i>0;i--)
    {
    for(j=1;j<=n-i;j++)
    {
    printf(" ");
    }
    printf("%d",i);
    for(k=0;k<=2*(i-2);k++)
    {
    printf(" ");
    }
    if(i>1)
    {
    printf("%d",i);
    }
    printf("\n");
    }
    return 1;
    }

    Reply

    UnknownDecember 29, 2019 at 4:42 PM
    #include
    main() {
    int i,j;
    for(i=1; i<=4; i++)
    {
    for(j=3; j>=i; j--) {
    printf(" "); }
    for(j=i; j>=1; j--)
    { if(j>=i)
    printf("%d",i);
    else
    printf("");}
    for(j=i*2-1;j>1;j--)
    { if(j-1>1)
    printf(" ");
    else
    printf("%d",i);
    }printf("\n");}
    for(i=3;i>=1;i--)
    {
    for(j=3;j>=i;j--)
    printf(" ");
    for(j=i;j>=1;j--)
    { if(j>=i)
    printf("%d",i);
    else
    printf(" ");
    }
    for(j=i-1;j>=1;j--)
    {
    if(j>1)
    printf(" ");
    else
    printf("%d",i);
    }
    printf("\n");
    }
    }

    ReplyDelete