943,962 Members | Top Members by Rank

Ad:
  • C Discussion Thread
  • Unsolved
  • Views: 8226
  • C RSS
Nov 2nd, 2009
0

Print star pattern

Expand Post »
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
Reputation Points: 10
Solved Threads: 0
Light Poster
seo2005 is offline Offline
28 posts
since Jun 2009
Nov 2nd, 2009
0
Re: Print star pattern
try two for loops...one embedded into the other

  1. for (i = 0; i < num; ++i)
  2. {
  3. for (j = 0; j < num2; ++j)
  4. {}
  5. }
Reputation Points: 499
Solved Threads: 367
Postaholic
gerard4143 is offline Offline
2,196 posts
since Jan 2008
Nov 2nd, 2009
0
Re: Print star pattern
Click to Expand / Collapse  Quote originally posted by gerard4143 ...
try two for loops...one embedded into the other

  1. for (i = 0; i < num; ++i)
  2. {
  3. for (j = 0; j < num2; ++j)
  4. {}
  5. }
Thanks for quick reply. What do you mean by num and num2 in the above code. Will i have to declare num and num2.
Reputation Points: 10
Solved Threads: 0
Light Poster
seo2005 is offline Offline
28 posts
since Jun 2009
Nov 2nd, 2009
0
Re: Print star pattern
Click to Expand / Collapse  Quote originally posted by seo2005 ...
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.
Reputation Points: 499
Solved Threads: 367
Postaholic
gerard4143 is offline Offline
2,196 posts
since Jan 2008
Nov 2nd, 2009
1
Re: Print star pattern
Click to Expand / Collapse  Quote originally posted by gerard4143 ...
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.

Quote ...
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.
Last edited by Aia; Nov 2nd, 2009 at 1:18 am.
Aia
Reputation Points: 2224
Solved Threads: 218
Nearly a Posting Maven
Aia is offline Offline
2,304 posts
since Dec 2006
Dec 27th, 2009
-1
Re: Print star pattern
Click to Expand / Collapse  Quote originally posted by seo2005 ...
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();
}
Reputation Points: 6
Solved Threads: 0
Newbie Poster
krishnendu21 is offline Offline
1 posts
since Dec 2009
Jul 26th, 2011
-2
Re: Print star pattern
void main()
{
int i,j;
clrscr();
for(i=4;i>=1;i--)
{
printf("\n");
for(j=1;j<=i;j++)
printf("*");
}
}
Reputation Points: 2
Solved Threads: 0
Newbie Poster
archi vachhani is offline Offline
1 posts
since Jul 2011

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
This thread is currently closed and is not accepting any new replies.
Previous Thread in C Forum Timeline: Can someone help me please :'(
Next Thread in C Forum Timeline: help on rand() srand() pls.





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC