0

I'm a beginner to programming (learning python right now). Ran across this question, and am completely lost as to how to get the algorithm and how to write it in pseudocode.

I'm sorry for asking. I'd really like some help though and would appreciate any help at all.

Memo Smith
  • 69
  • 4

1 Answers1

0

For positive integers multiplication can be replaced by addition. For example: 3 x 4 = 3 + 3 + 3 + 3

You can then replace multiple additions with a loop, for example

int result = 0
int a = 3
int b = 4

// calculate a x b
for 1 .. b
        result = result + a
end for

So the loop works like this

result = 0 + 3
result = 3 + 3
result = 6 + 3
result = 9 + 3

print result   // 12
oleksii
  • 35,458
  • 16
  • 93
  • 163
  • 1
    *"Multiplication can be replaced by addition"* - for non-negative integers only, though. – Pang Apr 09 '15 at 02:47