We're a community of 1077K IT Pros here for help, advice, solutions, professional growth and fun. Join us!
1,076,278 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Start New Discussion Reply to this Discussion

Print star pattern

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

5
Contributors
6
Replies
1 Year
Discussion Span
1 Year Ago
Last Updated
7
Views
seo2005
Light Poster
28 posts since Jun 2009
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 0

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

for (i = 0; i < num; ++i)
{
for (j = 0; j < num2; ++j)
{}
}
gerard4143
Nearly a Posting Maven
2,295 posts since Jan 2008
Reputation Points: 512
Solved Threads: 397
Skill Endorsements: 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.

seo2005
Light Poster
28 posts since Jun 2009
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 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.

gerard4143
Nearly a Posting Maven
2,295 posts since Jan 2008
Reputation Points: 512
Solved Threads: 397
Skill Endorsements: 0

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.

Aia
Nearly a Posting Maven
2,394 posts since Dec 2006
Reputation Points: 2,224
Solved Threads: 220
Skill Endorsements: 14

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();
}

krishnendu21
Newbie Poster
1 post since Dec 2009
Reputation Points: 6
Solved Threads: 0
Skill Endorsements: 0
void main()
{
         int i,j;
         clrscr();
         for(i=4;i>=1;i--)
         {
             printf("\n");
             for(j=1;j<=i;j++)
                printf("*");
          }
}
archi vachhani
Newbie Poster
1 post since Jul 2011
Reputation Points: 2
Solved Threads: 0
Skill Endorsements: 0

This article has been dead for over three months: Start a new discussion instead

Post: Markdown Syntax: Formatting Help
 
You
 
© 2013 DaniWeb® LLC
Page rendered in 0.0683 seconds using 2.65MB