Welcome to Dream.In.Code
Getting C++ Help is Easy!

Join 132,670 C++ Programmers for FREE! Get instant access to thousands of C++ experts, tutorials, code snippets, and more! There are 1,175 people online right now. Registration is fast and FREE... Join Now!




pls explain for loop output

 
Reply to this topicStart new topic

pls explain for loop output, for loop

grungekaze
post 17 Jul, 2007 - 02:08 AM
Post #1


New D.I.C Head

*
Joined: 14 Jul, 2007
Posts: 1


My Contributions


the output is like this:
if n=5

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

pls...... explain how for loop executes this one?
im just a newbie of C.
User is offlineProfile CardPM

Go to the top of the page

no2pencil
post 17 Jul, 2007 - 03:10 AM
Post #2


My fridge be runnin OH NOEZ!

Group Icon
Joined: 10 May, 2007
Posts: 6,354



Thanked 58 times

Dream Kudos: 2375

Expert In: Goofing Off

My Contributions


QUOTE(grungekaze @ 17 Jul, 2007 - 03:08 AM) *

the output is like this:
if n=5

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

pls...... explain how for loop executes this one?
im just a newbie of C.


You would need to have a counter & during each you will print an '*' charactor for the value of the counter. At the end of each loop, decrease the counter by one. You will also need a 2nd counter to add the spaces, which will increase at the end of each loop.

Good luck!
User is offlineProfile CardPM

Go to the top of the page

enpey
post 17 Jul, 2007 - 03:40 AM
Post #3


D.I.C Head

**
Joined: 2 May, 2007
Posts: 59



Thanked 1 times
My Contributions


You wouldn't need a second counter for the spaces, as there is no problem in this simple program with just adding a space character after every *, eg:

CODE

printf ("* ");


User is offlineProfile CardPM

Go to the top of the page

Reply to this topicStart new topic
Time is now: 11/23/08 06:00AM

Live C++ Help!

C++ Tutorials

Reference Sheets

C++ Snippets

Bye Bye Ads

Free DIC T-Shirt

T-Shirt Example

Related Sites

Monthly Drawing

Thumb Drive

Partners

Top Contributors

Top 10 Kudos This Month