![]() |
|
#1
|
|||
|
|||
Star PatternsHello all,
I have a problem in printing a certain patteren "as showed in the attachments. Here is my tries so far CPP / C++ / C Code:
Please help |
|||
|
#2
|
|||
|
|||
Re: Star PatternsI think it would be a good ideas for you to do this:
CPP / C++ / C Code:
|
|
#3
|
|||
|
|||
Re: Star PatternsNow it does not make the shapes I wanted
... at first it did but it did two identical ones although the conditions are different it's a tricky code for a begginer lol any help and remarks to achieve the output attached would be highly appreciated |
|
#4
|
|||
|
|||
Re: Star PatternsQuote:
As for the conditions being different and the shape being same... Look at the code you have in your loops. It's identical in both. How could it possibly produce anything but identical results? |
|
#5
|
|||
|
|||
Re: Star PatternsOh I'm sorry
It must have slipped off the attachments Please look into the attached file --to this post-- |
|
#6
|
|||
|
|||
Re: Star PatternsIt's pretty simple. Effectively you have to play around with printing spaces and printing stars. For example, in the shape you already managed to print, you first print one star and 4 spaces, then 2 stars and 3 spaces, then 3 stars and 2 spaces etc. Or to put it another way, on the first iteration (the first run through your outer for loop) you print 1 star, on the second you print 2 stars etc. Or to put it yet another way... If the current iteration number of the inner loop is smaller or equal to the current iteration number of the outer loop, print a star.
So, as an example, let's say the outer loop iteration number is 4. You enter the inner loop, the iteration number is 1. 1 <= 4 is true, so you print a star. Once the inner loop number goes to 5, you print a space which is exactly as it should be, since the outer loop number represents also the line number you're at. Still following? As an example, here are the first two shapes based on this logic. CPP / C++ / C Code:
|
Recent GIDBlog
Vista ?Widgets? on Windows XP by LocalTech
| Thread Tools | Search this Thread |
| Rate This Thread | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| A weird problem of namespace | meili100 | C++ Forum | 1 | 12-Feb-2008 22:47 |
| FLTK - Can't fill in my star . . . | Louis11 | FLTK Forum | 6 | 01-Nov-2007 18:12 |
| Print diamond shaped star pattern | Zayne | C++ Forum | 7 | 23-Apr-2006 13:00 |
| Diamond Shape of Star (*) Symbols | Zayne | C++ Forum | 2 | 21-Apr-2006 15:29 |
| TOP PACKAGE: 20GB Diskspace | 700GB Diskspace | Hosting star | UWebSmart | Web Hosting Advertisements & Offers | 0 | 23-Jan-2006 15:23 |
Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The