2 Replies - 4896 Views - Last Post: 17 July 2007 - 04:40 AM Rate Topic: -----

#1 grungekaze  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 14-July 07

pls explain for loop output

Post icon  Posted 17 July 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.
Is This A Good Question/Topic? 0
  • +

Replies To: pls explain for loop output

#2 no2pencil  Icon User is offline

  • Dic Head
  • member icon

Reputation: 5163
  • View blog
  • Posts: 26,830
  • Joined: 10-May 07

Re: pls explain for loop output

Posted 17 July 2007 - 04:10 AM

View Postgrungekaze, on 17 Jul, 2007 - 03:08 AM, said:

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!
Was This Post Helpful? 0
  • +
  • -

#3 enpey  Icon User is offline

  • D.I.C Head

Reputation: 7
  • View blog
  • Posts: 75
  • Joined: 02-May 07

Re: pls explain for loop output

Posted 17 July 2007 - 04:40 AM

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:

printf ("* ");


Was This Post Helpful? 0
  • +
  • -

Page 1 of 1