Victor said:
If multiplication is not available on your hardware, then you create a loop
in which you add 'a' to 'a' (b-1) times. That's what they were supposed to
teach you in grade school.
That wasn't how I was taught multiplication in primary school.
Where are you from, the Roman Empire?
We have positional systems these days.
As they teach you in computer class, repeated addition is a really poor
algorithm,
since the runtime is proportional to the value of the number.
You should at least get runtime proportional to the log of the value of
the number,
as Ivan's method showed.
Of course my favourite multiplication algorithm is slightly different.
(a+b)*(a+b) = (a*a)+(b*b)+(2*a*b)
Therefore:
ab = (square_table[a + b] - square_table[a] - square_table
) >> 1;
You just need the square_table to be big enough.
Carl.