Search C Program

Number Pattern - 25

11111
2222
333
22
1

#include<stdio.h>
int main()
{
  int i,j;
  for(i=1;i<=5;i++)
  {
    for(j=5;j>=i;j--)
    {
      if(i<=3)
        printf("%d",i);
      else
        printf("%d",6-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


5 comments:

  1. what if number of rows are entered by user??

    ReplyDelete
    Replies
    1. take input of n, and then replace 5 by n, 3 by n/2 + 1 and 6 by n+1. it should work.

      Delete
  2. #include
    #include
    #include

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

    for(i=1;i<=5;i++)
    {
    for(j=i;j<=5;j++)
    {
    printf("%d",3-abs(3-i));
    }

    printf("\n");


    }
    return 0;
    }


    better way of doing this!!

    ReplyDelete
  3. int main()
    {
    int i = 1;
    int k = 1;
    while (i <= 5)
    {

    for (int j = i; j <= 5; j++)
    {
    printf("%d",k);
    }
    i += 1;
    printf("\n");
    if (i > 3)
    {
    k -= 1;
    }
    else
    {
    k += 1;
    }
    }

    return 0;
    }

    ReplyDelete
  4. #include

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

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

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

    ReplyDelete