-->

program to display star pattern

//program to display following star pattern.
//              *
//           * *                                                                                                          
//        * * *
//     * * * *
//  * * * * *   
#include<stdio.h>
#include<conio.h>
void main()
{
clrscr();
int i,j,k,sp;
 for(i=1;i<=5;i++)
   { sp=i;
         for(k=sp;k<=10;k++)
           {
               
                     printf(" ");

              }
                     
    for(j=1;j<=i;j++)
                       {
                       printf("*");
                     }      
    printf("\n"); 
}
getch();
}
---------------------------------
logics in mind
-------------------------------
1)we have to display *,**,***, and so  on .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(maximum) with display of stars(above).
3)if we look carefully to given pattern we can see there space decreased after each display. for this, we have used loop. in each display, it decreases space and then it goes for next display. To decrease space, it taks value from outer loop i.e. value from variable 'i'.
3)First loop(outer) takes value 1 and assigns to inner.The inner executes 1 time/s 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

.

No comments:

Post a Comment