-->

program to display following numeric/star pattern.

//program to display following numeric pattern.
//      5
//      44
//      333
//      2222
//      11111        
#include<stdio.h>
#include<conio.h>
void main()
{
int i,j;
for(i=5;>=1;i--)
  {
     for(j=5;j>=i;j--)
          {
                printf("%d",i);
          }
       printf("\n");
 }
getch();
}
--------------------------------------------------------
logics in mind:
----------------------
1)we have to display 5,then 44, 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 
two times  and it goes on decreasing.
3)First loop(outer) takes value 5 and assigns to inner.The inner executes one time with display taken from outer loop.
4)next time, the outer loop takes the value 4 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