Print star pattern

Please support our C advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: Jun 2009
Posts: 28
Reputation: seo2005 is an unknown quantity at this point 
Solved Threads: 0
seo2005 seo2005 is offline Offline
Light Poster

Print star pattern

 
0
  #1
Nov 2nd, 2009
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
Reply With Quote Quick reply to this message  
Join Date: Jan 2008
Posts: 430
Reputation: gerard4143 is on a distinguished road 
Solved Threads: 51
gerard4143's Avatar
gerard4143 gerard4143 is offline Offline
Posting Pro in Training
 
0
  #2
Nov 2nd, 2009
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. }
Reply With Quote Quick reply to this message  
Join Date: Jun 2009
Posts: 28
Reputation: seo2005 is an unknown quantity at this point 
Solved Threads: 0
seo2005 seo2005 is offline Offline
Light Poster
 
0
  #3
Nov 2nd, 2009
Originally Posted by gerard4143 View Post
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.
Reply With Quote Quick reply to this message  
Join Date: Jan 2008
Posts: 430
Reputation: gerard4143 is on a distinguished road 
Solved Threads: 51
gerard4143's Avatar
gerard4143 gerard4143 is offline Offline
Posting Pro in Training
 
0
  #4
Nov 2nd, 2009
Originally Posted by seo2005 View Post
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.
Reply With Quote Quick reply to this message  
Join Date: Dec 2006
Posts: 2,048
Reputation: Aia has much to be proud of Aia has much to be proud of Aia has much to be proud of Aia has much to be proud of Aia has much to be proud of Aia has much to be proud of Aia has much to be proud of Aia has much to be proud of Aia has much to be proud of Aia has much to be proud of 
Solved Threads: 179
Aia's Avatar
Aia Aia is offline Offline
Postaholic
 
1
  #5
Nov 2nd, 2009
Originally Posted by gerard4143 View Post
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.
Last edited by Aia; Nov 2nd, 2009 at 1:18 am.
Reply With Quote Quick reply to this message  
Reply

Message:




Views: 348 | Replies: 4
Thread Tools Search this Thread



Tag cloud for C
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC