//program to display following star pattern.
// *
// * *
// * *
// *
// * *
// * *
// * *
// * * * * * * * * **
// * * * * * * * * **
#include<stdio.h>
#include<conio.h>
void main()
{
clrscr();
int i,k,m;
for(i=1;i<=5;i++)
{
for(m=i;m<= i;m++)
{
printf("*");
}
for(m=1;m<i;m++)
{
printf(" ");
}
for(m=i;m<=i;m++)
{
if(m==1)
printf(" ");
else
printf("*");
}
printf("\n");
}
for(i=1;i<=10;i++)
{
printf("*");
}
getch();
}
----------------------------------
logic in mind
-----------------------------------
1.)The given pattern has three parts.
*
*
*
*
*
*
*
*
*
second part:
*
*
*
*
second part:
*
*
*
*
third part:
****************
If we combine them then we get given pattern.1)so for these three, we use three loops
2)since there are five asterisks we display using loop without space(see figure).
3)then we display second part with increasing space between them. For space, we have used loop.
3)then we display second part with increasing space between them. For space, we have used loop.
This part contains 'if' because we have to decide display first space rather asterisk so.
4) In third part, we use loop to display horizontally.
4) In third part, we use loop to display horizontally.
For more, look downside.
---------------------------------------------------------------------------------------
---------------------------------------------------------------------------------------
program's screenshot:
No comments:
Post a Comment