Web Analytics Made Easy -
StatCounter Can't figure out how to do this...please help - CodingForum

Announcement

Collapse
No announcement yet.

Can't figure out how to do this...please help

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Can't figure out how to do this...please help

    Write a Program that uses nested for loops to print the following multiplication table:

    1 2 3 4 5 6 7 8 9
    1 1
    2 2 4
    3 3 6 9
    4 4 8 12 16
    5 5 10 15 20 25
    6 6 12 18 24 30 36
    7 7 14 21 28 35 42 49
    8 8 16 24 32 40 48 56 64
    9 9 18 27 36 45 54 63 72 81

  • #2
    I mean, you're supposed to use nested for loops, but how do you set the inner loop so that it calculates the inside numbers?

    Comment


    • #3
      This type of homework assignment usually has two purposes. One purpose being to figure out the logic involved. In this case they want you to find the pattern in the data and determine what mathematical calculations you will need to perform to generate that data. The other purpose is learning how to use loops. Now you have tie the logic together with the use of the loops. Look at the numbers. What pattern do you see?

      1
      2 4
      3 6 9
      4 8 12 16

      What is happening here?

      When using loops you can nest loops to generate tables of data. One loop can be used to calculate the rows and the other loop can be used to calculate the columns. Look at the first column there. You see 1, 2, 3, 4, 5, 6... So what do you suppose one of those loops needs to do? Now look at the rows you see 2, 4 and then 3, 6, 9 and then 4 , 8 , 12, 16. So what do you suppose the other loop needs to do?
      Spookster
      CodingForum Supreme Overlord
      All Hail Spookster

      Comment


      • #4
        Read Spooksters post, then give it another shot. If you still can't get it to work, post your code here and we'll try to steer you in the right direction further by pointing out errors in your code.

        The answer to this problem is really only about 6 lines of code (minus formatting), it's the logic of how the nested loops work together that you have to understand.

        Good luck,
        Gox

        Comment

        Working...
        X