-->

program to display following numeric/star pattern.

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

No comments:

Post a Comment