//program to display following numeric pattern.
// 12345
// 1234
// 123
// 12
// 1
#include<stdio.h>
#include<conio.h>
void main()
{
int i,j;
for(i=5;i>=1;i--)
{
for(j=1;j<=i;j++)
{
printf("%d",j);
}
printf("\n");
}
getch();
}
--------------------------------------------------------
logics in mind:
----------------------
1)we have to display 1,2,3,4,5 so we use loop.
2)since the displays are in repetitive form ,,we set up the loop in nested form such that
internal loop executes 5 times with display of numbers(above).
3)First loop(outer) takes value 5 and assigns to inner.The inner executes 5 times with display.
4)next time, the outer loop takes the value 4 and transfers to inner loop, it displays again and again.
and it goes on
// 12345
// 1234
// 123
// 12
// 1
#include<stdio.h>
#include<conio.h>
void main()
{
int i,j;
for(i=5;i>=1;i--)
{
for(j=1;j<=i;j++)
{
printf("%d",j);
}
printf("\n");
}
getch();
}
--------------------------------------------------------
logics in mind:
----------------------
1)we have to display 1,2,3,4,5 so we use loop.
2)since the displays are in repetitive form ,,we set up the loop in nested form such that
internal loop executes 5 times with display of numbers(above).
3)First loop(outer) takes value 5 and assigns to inner.The inner executes 5 times with display.
4)next time, the outer loop takes the value 4 and transfers to inner loop, it displays again and again.
and it goes on
No comments:
Post a Comment