Write a program to print following pattern

12345

2345

345

45

5

Program code

#include <stdio.h>



int main()

{

    int i, j;

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

    {

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

        {

            printf("%d",j);

        }

        printf("\n");

    }



    return 0;

}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31

Step by Step solution

  1. Number of row -

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

#include <stdio.h>
int main()

{

    int i, j;

    for(i=1;i>=5;i++)

    
{......
 }



    return 0;

}

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
(adsbygoogle = window.adsbygoogle || []).push({});
  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=i;j<=5;j++)

        {

            printf("%d",j);

        }

        printf("\n");

 return 0;

}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
  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=i;j<=5;j++)

        {

            printf("%d",j);

        }

        printf("\n");
...................


    return 0;
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
var Tawk_API=Tawk_API||{}, Tawk_LoadStart=new Date(); (function(){ var s1=document.createElement("script"),s0=document.getElementsByTagName("script")[0]; s1.async=true; s1.src='https://embed.tawk.to/5bd7b562476c2f239ff683f0/default'; s1.charset='UTF-8'; s1.setAttribute('crossorigin','*'); s0.parentNode.insertBefore(s1,s0); })();
(adsbygoogle = window.adsbygoogle || []).push({});