# Write a program to print following pattern
5
54
543
5432
54321
# Program code
#include <stdio.h>
int main()
{
int i, j;
for(i=5;i>=1;i--)
{
for(j=5;j>=i;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
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
# Step by Step solution
Number of row
Is has 5 row , so first loop will execute for 5 time
#include <stdio.h>
int main()
{
int i, j;
for(i=5;i>=1;i--)
{......
}
return 0;
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
- 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=5;j>=i;j--)
{
printf("%d",j);
}
printf("\n");
}
1
2
3
4
5
6
7
8
9
10
11
12
13
2
3
4
5
6
7
8
9
10
11
12
13
- Number of column
It has 5 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=5;j>=i;j--)
{
printf("%d",j);
}
printf("\n");
...................
return 0;
1
2
3
4
5
6
7
8
9
10
11
12
2
3
4
5
6
7
8
9
10
11
12