Search C Program | nimishsoft@gmail.com

Number Pattern - 14

1234567
12345
123
1

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


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


14 comments:

  1. The above program is conceptually incorrect. It will run only for 7.
    Here is a generic program that will run for any number of rows ->

    void numberPatternC(int rows) {
    int i;
    int j;
    int count = 1;
    for(i=1; i<rows; i++) {
    count = count + 2;
    }
    for(i=0; i<rows; i++) {
    for(j=1; j<=count; j++) {
    System.out.print(j);
    }
    System.out.println();
    count = count - 2;
    }
    }

    ReplyDelete
    Replies
    1. you can use variable to store any dynamic value and use that in loop

      Delete
    2. That is not very kind to say it is incorrect. Surely the pattern starts at number 7 then decrease it by 2. It did not ask to write a program that will start at a particular number. Be very kind as to not
      criticise someone. The program above works and it's beautiful.

      Delete
  2. #include
    #include
    void main()
    {
    int i,j,n;
    clrscr();
    for(i=3;i>=0;i--)
    {
    n=2*i+1;
    for(j=1;j<=n;j++)
    {
    printf("%d",j);
    }
    printf("\n");
    }
    getch();
    }
    //////////// sir, i think its simple :)

    ReplyDelete
  3. //////the more simpler program
    #include
    int main()
    {
    int i,j,n=7;
    for(i=1; i<=4; i++)
    {
    for(j=1; j<=n; j++)
    printf("%d",j);
    n-=2;
    printf("\n");
    }
    return 0;
    }

    ReplyDelete
  4. #include
    #include
    void main()

    {
    int i, j;
    for(i=7;i>=1;i--)
    {
    if(i%2 != 0)
    {
    for(j=1;j<=i;j++)
    {
    printf("%d",j);
    }
    printf("\n");
    }

    }

    getch();


    }

    ReplyDelete
  5. this program logic is first for(i=3;i>=1;i--)
    {
    for(j=1;j<=(i*3+1);j++)
    {
    s.o.pln(j);
    }

    ReplyDelete
  6. #include

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

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

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

    return 0;
    }

    ReplyDelete
  7. Ysuppdelturpu Cindy Collins link
    condculgepi

    ReplyDelete