Computer Science Canada Multiplication table

Author:  Punde [ Wed Feb 12, 2003 2:56 pm ]
Post subject:  Multiplication table

Hello there,
I just joined this forum because I think it will help me a lot in Turing, which is what I am learning at the moment, anyways I have a question.
I am trying to do a multiplication table that displays the multiplication numbers from 1 to 19, however I don't know how to actually multiply them using for loops.
I have the following code:
 code: setscreen ( "text:25;90" ) put "      ".. for i:1..19 put i:4.. end for put "" put repeat ("-", 82).. put "" for a: 1..19 put a:4, "|" end for

THe table has to look something like this:
-- 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
1 1 2 3
2 2 4
3 3
4 4
5
6
7
8
9
...
and so on. Can anyone please help me with this? Thanks.

Author:  Tony [ Wed Feb 12, 2003 3:50 pm ]
Post subject:

basically you next a forloop inside another forloop like this

 code: for r:1..19     for c:1..19     put r*c:4, "|"..     end for put "" end for

For each of 19 rows (for r) there will be 19 columns (for c). In that space we put the product of the row number * column number

the put "" at the end of inside loop makes a new line so we move on to the next row.

You'll be using nested loops in many of your future programs

 Author: Punde [ Thu Feb 13, 2003 1:17 pm ] Post subject: Thanks, but with the code you gave me I only get the actual multiplication but not the numbers on the top with the -------, nor the line on the left with the |. Can you help me with this little part?? Thx.

Author:  Tony [ Thu Feb 13, 2003 1:49 pm ]
Post subject:

for that you can use your own code...

there shouldn't be any probem of adding the top part to it. Just copy your code and place it in front of nested loops.

Now if you do a little modification to the nested loops, you can also draw a vetrical line in font of the table.

paste a line of code to put the numbers and | right after for r:1..19

where R would be your number.

 code: %YOUR CODE PART BELOW put "      ".. for i:1..19 put i:4.. end for put "" put repeat ("-", 82).. %MY CODE PART BELOW for r:1..19 put r:4,"|"..  %<--- add this     for c:1..19     put r*c:4, "|"..     end for put "" end for

 Author: Punde [ Thu Feb 13, 2003 1:55 pm ] Post subject: Oh I see, Thank you very much

 :