-->

program to display following numeric/star pattern.

//program to display following numeric/star pattern.
//     11111
//     2222
//     333
//     44
//     5            
#include<stdio.h>
#include<conio.h>
void main()
{
int i,j;
for(i=1;<=5;i++)
  {
     for(j=5;j>=i;j--)
          {
                printf("%d",i);
          }
       printf("\n");
 }
getch();
}
--------------------------------------------------------
logics in mind:
----------------------
1)we have to display 1,then 2222, then 333,so on.  we use loop for this.
 2)since the displays are in repetitive form ,,we set up the loop in nested form such that
        internal loop executes first  time with display of numbers(above) which it takes from outer loop,then 
four times  and it goes on decreasing.
3)First loop(outer) takes value 1 and assigns to inner.The inner executes five times with display taken from outer loop.
4)next time, the outer loop takes the value 2 and transfers to inner loop, it displays number taken from outer loop again and again.and it goes on.
............................................................................................
if you want to display "*" then use "*" in printf function.

No comments:

Post a Comment