1,105,578 Community Members

Print star pattern

Member Avatar
seo2005
Light Poster
28 posts since Jun 2009
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

Hi,

I would like to print star pattern in the following way -

****
***
**
*

main()

int i;

clrscr();

for(i=4;i<=4;i++)

{

printf("*");

getch();

}

It prints starts like ****

I don't know how to complete the program. Can anyone please do the complete program for this so that stars are printed in the manner as given above.

Thanks

Member Avatar
gerard4143
Nearly a Posting Maven
2,385 posts since Jan 2008
Reputation Points: 371 [?]
Q&As Helped to Solve: 409 [?]
Skill Endorsements: 0 [?]
 
0
 

try two for loops...one embedded into the other

for (i = 0; i < num; ++i)
{
for (j = 0; j < num2; ++j)
{}
}
Member Avatar
seo2005
Light Poster
28 posts since Jun 2009
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

try two for loops...one embedded into the other

for (i = 0; i < num; ++i)
{
for (j = 0; j < num2; ++j)
{}
}

Thanks for quick reply. What do you mean by num and num2 in the above code. Will i have to declare num and num2.

Member Avatar
gerard4143
Nearly a Posting Maven
2,385 posts since Jan 2008
Reputation Points: 371 [?]
Q&As Helped to Solve: 409 [?]
Skill Endorsements: 0 [?]
 
0
 

Thanks for quick reply. What do you mean by num and num2 in the above code. Will i have to declare num and num2.

Its just an example that I made up..The numbers signify nothing.

Member Avatar
Aia
Nearly a Posting Maven
2,307 posts since Dec 2006
Reputation Points: 1,977 [?]
Q&As Helped to Solve: 236 [?]
Skill Endorsements: 20 [?]
 
1
 

Its just an example that I made up..The numbers signify nothing.

It doesn't matter, if she follows your advise she will get a square.

Can anyone please do the complete program for this so that stars are printed in the manner as given above.

Then you'll learn nothing.

Some clue:
One loop inside another one as previously said.
Outer loop is the number of rows.
Inside loop number of stars for each row printed minus one less than previous row.

Member Avatar
krishnendu21
Newbie Poster
1 post since Dec 2009
Reputation Points: -4 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
-1
 

Hi,

I would like to print star pattern in the following way -

****
***
**
*

main()

int i;

clrscr();

for(i=4;i<=4;i++)

{

printf("*");

getch();

}

It prints starts like ****

I don't know how to complete the program. Can anyone please do the complete program for this so that stars are printed in the manner as given above.

Thanks

hey u may try this..
#include<stdio.h>
#include<conio.h>
void main()
{int i,j;
clrscr();
for(i=1;i<=4;i++)
{
for(j=1;j<=5-i;j++)
{
printf("*");
}
printf("\n");
}
getch();
}

Member Avatar
archi vachhani
Newbie Poster
1 post since Jul 2011
Reputation Points: -8 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
-2
 
void main()
{
         int i,j;
         clrscr();
         for(i=4;i>=1;i--)
         {
             printf("\n");
             for(j=1;j<=i;j++)
                printf("*");
          }
}
You
This article has been dead for over three months: Start a new discussion instead
Post:
Start New Discussion
Tags Related to this Article