how to display this shape using for loop?

Please support our C++ advertiser: Intel Parallel Studio Home
Thread Solved

Join Date: Oct 2009
Posts: 63
Reputation: samsons17 is an unknown quantity at this point 
Solved Threads: 1
samsons17 samsons17 is offline Offline
Junior Poster in Training

how to display this shape using for loop?

 
0
  #1
Nov 9th, 2009
how to display this output ?

**********
*********
********
*******
******
*****
****
***
**
*
**
***
****
*****
******
*******
********
*********
**********




thank you...
Reply With Quote Quick reply to this message  
Join Date: Oct 2009
Posts: 133
Reputation: restrictment is on a distinguished road 
Solved Threads: 10
restrictment's Avatar
restrictment restrictment is offline Offline
Junior Poster
 
0
  #2
Nov 9th, 2009
Please show effort in trying to make the shape, and I will help you.
Reply With Quote Quick reply to this message  
Join Date: Dec 2008
Posts: 1,417
Reputation: firstPerson is just really nice firstPerson is just really nice firstPerson is just really nice firstPerson is just really nice firstPerson is just really nice 
Solved Threads: 182
firstPerson's Avatar
firstPerson firstPerson is offline Offline
Nearly a Posting Virtuoso
 
0
  #3
Nov 9th, 2009
Here is a hint :
  1. ********** 10 stars
  2. ********* 9 stars
  3. ******** 8 stars
  4. ******* 7 stars
  5. ****** 6 stars
  6. ***** 5 stars
  7. **** 4 stars
  8. *** 3 stars
  9. ** 2 stars
  10. * 1 stars
  11. ** 2 stars
  12. *** 3 stars
  13. ****
  14. *****
  15. ******
  16. *******
  17. ********
  18. *********
  19. ********** 10 stars

So you see that they decrease by 1 star until they reach 1 then they
start increment.

so assuming you can separate this problem into 2 blocks, you can
do something like this :

  1. for(int i = 10; i != 1; i--)
  2. printStars(i); //a function that prints i stars with endl
  3. for(int i = 2; i <= 10; i++)
  4. printStars(i);

Now what should your printStars look like :
for example if one calls printStars(4) it should output the following :
  1. ****

Go ahead and try to devise printStars then you problem becomes much
easier.
1) What word becomes shorter if you add a letter to it? [ Solved by : niek_e, Paul Thompson, SgtMe, murtan, xavier666, jonsca, orangejediman]
2) What does this sequence  equal to :  (.5u - .5a)(.5u-.5b)(.5u-.5c) ...[*solved by : murtan, xavier666]
3) What is the 123456789th prime numer?
Reply With Quote Quick reply to this message  
Join Date: Sep 2009
Posts: 69
Reputation: tkud is an unknown quantity at this point 
Solved Threads: 14
tkud's Avatar
tkud tkud is offline Offline
Junior Poster in Training

re

 
-1
  #4
Nov 9th, 2009
This should do...

  1. #include<iostream>
  2. using namespace std;
  3. void printstar(int num_of_times);
  4. void reverseprint(int highest);
  5. int main()
  6. {
  7. for(int i=0;i<10;i++){
  8. printstar(i);
  9. }
  10. reverseprint(10);
  11. return 0;
  12. }
  13.  
  14. void printstar(int num_of_times){
  15. for(int i=0;i<num_of_times;i++){
  16. cout<<"* ";
  17. }
  18. cout<<endl;
  19. }
  20.  
  21. void reverseprint(int highest){
  22. for(int i=0;i<highest;i++){
  23. int x=highest-i;
  24. printstar(x);
  25. }
  26. cout<<endl;
  27. }
Please, if this satisfies your problem,mark this thread as solved.Thanks
"Show me your code and i will tell you who you are.."---Tkud
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



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

©2003 - 2009 DaniWeb® LLC