Write a program to display multiplication table from two to nine for example: 2 x 1 = 2 2 x 2 = 4 2 x 3 = 6 2 x 4 = 8 2 x 5 = 10 2 x 6 = 12 2 x 7 = 14 2 x 8 = 16 2 x 9 = 18 2 x 10 = 20
okay, this is pretty straight forward. here's some Java-like pseudocode: accumulator = 0; for (n = 1; n <= 9; ++n) { accumulator += 2; print("2 x " + n + " = " + accumulator); }
i don't understand accumulator
Ok thank
accumulator increments by 2 each iteration so for n = 1 it'll be 2 then for n = 2 it'll be 2 + 2 = 4 then for n = 3 it'll be 4 + 2 = 6 then for n = 4 it'll be 6 + 2 = 8
since we're iterating thru all the products it's cheaper to just keep adding 2 than to multiply 2 * n separately each time
Ok i'm testing ....
Join our real-time social learning platform and learn together with your friends!