Computer Science Canada Creating a diagonal periodic table |
Author: | Krocker [ Mon Oct 07, 2013 3:22 pm ] | ||
Post subject: | Creating a diagonal periodic table | ||
ok so i have to create a diagonal multiplication table, i have managed to make the full table, but unable to get it diagonal. Something like this (table for 7s) 1 2 4 3 6 9 4 8 12 16 5 10 15 20 25 6 12 18 24 30 36 7 14 21 28 35 42 49 but i have 1 2 3 4 5 6 7 2 4 6 8 10 12 14 3 6 9 12 15 18 21 4 8 12 16 20 24 28 5 10 15 20 25 30 35 6 12 18 24 30 36 42 7 14 21 28 35 42 49 Heres my code so far:
|
Author: | DemonWasp [ Mon Oct 07, 2013 4:24 pm ] |
Post subject: | RE:Creating a diagonal periodic table |
Well, on the first row (i == 1) you want the inner loop to print exactly one number. On the second row (i == 2) you want the inner loop to print exactly two numbers. Do you see a pattern? How would you implement that pattern? |
Author: | Krocker [ Mon Oct 07, 2013 5:13 pm ] |
Post subject: | RE:Creating a diagonal periodic table |
ok, so, each row would increase by one, i got that, so # of r== i, but i cant seem to figure out how to imply that to a for loop. The only way i can think of is by using an if statement, however, im only allowed to use for statements. Also, the max number expected is 10, so thats not a problem |
Author: | Raknarg [ Mon Oct 07, 2013 7:00 pm ] |
Post subject: | RE:Creating a diagonal periodic table |
You just said it yourself, the j loop can only go up to whatever loop i is at. |
Author: | Krocker [ Mon Oct 07, 2013 7:28 pm ] |
Post subject: | RE:Creating a diagonal periodic table |
ya i figured it out, i made j > row, where row increases by one every time a row is done. It worked! Thanks. |