/*program to display following star pattern.
* * * * * *
* * * *
* * *
* *
*
*
* *
* * *
* * * *
* * * * *
*/
#include<stdio.h>
#include<conio.h>
void main(void)
{
clrscr();
int i,j,k,sp=1;
//printf("for upper part");
for(i=1;i<=5;i++)
{
for(k=sp;k<=i;k++)
{
printf(" ");
}
for(j=5;j>=i;j-- )
{
printf(" *");
}
printf("\n");
}
//printf("for lower part");
sp=5;
for(i=1;i<=5;i++)
{
for(k=sp;k>=i;k=k-1)
{ printf(" ");
}
for(j=1;j<=i;j++)
{
printf(" *");
}
printf("\n");
}
getch();
}
-------------------------------
logic in mind:-
---------------------------------
1)First loop is for number of rows.
2)like other programs, we display first upper part.
For this, we, first, display space (second loop)and then star(third loop.
3)For second part, we display first space(look diagram) using loop then we display star.
------------------------------------------------------------------------------------------------------------------------------
program's screenshot:-
programs output:-
* * * * * *
* * * *
* * *
* *
*
*
* *
* * *
* * * *
* * * * *
*/
#include<stdio.h>
#include<conio.h>
void main(void)
{
clrscr();
int i,j,k,sp=1;
//printf("for upper part");
for(i=1;i<=5;i++)
{
for(k=sp;k<=i;k++)
{
printf(" ");
}
for(j=5;j>=i;j-- )
{
printf(" *");
}
printf("\n");
}
//printf("for lower part");
sp=5;
for(i=1;i<=5;i++)
{
for(k=sp;k>=i;k=k-1)
{ printf(" ");
}
for(j=1;j<=i;j++)
{
printf(" *");
}
printf("\n");
}
getch();
}
-------------------------------
logic in mind:-
---------------------------------
1)First loop is for number of rows.
2)like other programs, we display first upper part.
For this, we, first, display space (second loop)and then star(third loop.
3)For second part, we display first space(look diagram) using loop then we display star.
------------------------------------------------------------------------------------------------------------------------------
program's screenshot:-
programs output:-
No comments:
Post a Comment