Thread: Nested Loops

  1. #1
    Registered User
    Join Date
    Aug 2012
    Posts
    2

    Nested Loops

    Hi, I have homework on a c problem.

    I have been asked to create a program that uses nested loops to create the following output.

    $
    $$
    $$$
    $$$$
    $$$$$

    Any suggestions?

    Thanks!!

  2. #2
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    Quote Originally Posted by wstayman View Post
    Hi, I have homework on a c problem.

    I have been asked to create a program that uses nested loops to create the following output.

    $
    $$
    $$$
    $$$$
    $$$$$

    Any suggestions?

    Thanks!!
    Welcome to the forum, Wstayman!

    This is how I approach all small puzzles like this:

    1) Unless you know how to solve it just from the introduction, grab a paper and pen, and forget the computer.

    2) If it's not easy, make an easy similar example problem first, and solve it on paper with pen.

    3) Note the steps you're using to solve it, VERY carefully. Repeat as needed. Before long, you will see the pattern you are using to solve it.

    4) Break that pattern down into small steps. You want to change the big steps that a human might use, to the small steps a computer program can use.

    These small steps, become the backbone of your pseudo code for your computer program.

    5) Putting off the details as much as you can, transfer your pseudo code, into actual code, and refine the overall flow of the program.

    Test it, to be sure it's basically correct.

    6) Add in the details and check that everything still works as it should. Your testing here should be quite thorough.


    These "nested loops" problems go well if you think about the outer for loop, as the loop for the rows (and controlling the rows), and the inner for loop as the loop for the individual printout for each column, in the current row.

    Try working along these lines, and remember - practice builds proficiency, and that's certainly true with learning to solve problems like this.

  3. #3
    Registered User
    Join Date
    Aug 2012
    Posts
    2
    Thank you so much for that!!!

    I have successfully created the output by just doing what you said.

    Thanks again!!

  4. #4
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    Quote Originally Posted by wstayman View Post
    Thank you so much for that!!!

    I have successfully created the output by just doing what you said.

    Thanks again!!
    Very good, and you are welcome!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Nested loops
    By laurenlb in forum C Programming
    Replies: 5
    Last Post: 03-02-2011, 12:49 AM
  2. nested four loops
    By begginer in forum C Programming
    Replies: 12
    Last Post: 02-25-2011, 11:21 PM
  3. Help nested for loops
    By dals2002 in forum C Programming
    Replies: 14
    Last Post: 03-14-2008, 01:18 AM
  4. Need help, nested loops
    By engstudent363 in forum C Programming
    Replies: 2
    Last Post: 02-17-2008, 10:23 PM
  5. nested for loops
    By Unregistered in forum C Programming
    Replies: 4
    Last Post: 11-17-2001, 11:44 AM

Tags for this Thread