Search C Program

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



4 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. 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
  3. #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