-->

wap to display star pattern

/*program to display following

* * * * *
    * * * * *
* * * * *
         * * * * *
             * * * * *

*/
#include<stdio.h>
#include<conio.h>
void main()
{
clrscr();
int i,j,k;
for(i=5;i>=1;i--)      //for number of rows. there are five rows so loop moves fives times
  {
    for(k=i;k<=7;k++)
      {
      printf(" ");   // this part is for space. every time , on display, it increases space.
      }
    for(j=1;j<=5;j++) //it displays star five times.It displays in columns
      {
printf("* ");
      }
    printf("\n");
}
getch();
}
---------------------------
logic in mind:-
----------
it has three parts:
first is number of rows
second part is number of columns
third part increasing space on each display.
1)fist loop is used for number of rows
2) the inner loop is for space to display
3)the inner most is for star display everytime.
------------------------------------------------------
program screenshot


output is






No comments:

Post a Comment