Santosh Dahal

print pattern in c - number pattern -1

Write a program to print following pattern

123456

12345

1234

123

12

1

Program code

#include <stdio.h>
int main()
{

    int i, j;
    for(i=6;i>=1;i--)
     {

        for(j=1;j<=i;j++)

        {

            printf("%d",j);

        }

        printf("\n");

    }



    return 0;

}

Step by Step solution

  1. Number of row

    Is has 6 row , so first loop will execute for 6 time

#include <stdio.h>
int main()

{

    int i, j;

    for(i=6;i>=1;i--)

    
{......
 }



    return 0;

}
  1. Number of character

It has only one type of character , so there will be only one nested loop

#include <stdio.h>
int main()

{

......
 for(j=1;j<=i;j++)

        {

            printf("%d",j);

        }

 return 0;

}

  1. Number of column

It has 6 maximum column and is decreasing with row number , so the nested loop decrease it's repetation with increase in row

#include <stdio.h>

............
        for(j=1;j<=i;j++)

        {

            printf("%d",j);

        }
...................


    return 0;