wanna help me "cheat?"

Hi guys, this is giving me a little bit of trouble.  its a stupid
algorithm to add two numbers.  I decided to script it to help me
with both the algorithm and REBOL.  This is a very easy one, but I
figure that if I have a handle on this one, the harder ones will be
that much easier...

======================================

given: m is greater than or equal to 1 and two positive numbers each
containing m digits, (a-sub(m-1)), (a-sub(m-2)),.....(a-sub(0)), and
(b-sub(m-1)), (b-sub(m-2)),.....(b-sub(0))

wanted: (c-sub(m)) (c-sub(m-1)) (c-sub(m-2).....(c-sub(0))

algorithm:

step 1 set the value of carry to 0

step 2 set the value of i equal to the value of 0

step 3 repeat the instructions in steps 4 thru 6 until the value of i
is greater than the value of (m-1)

step 4 add the two digits (a-sub(i)) and (b-sub(i) to the current
value of carry to get (c-sub(i))

step 5 if (c-sub(i)) >= 10, then reset (c-sub(i)) to ((c-sub(i))-10)
and reset the value of carry to 1, otherwise, set the new value of
carry to 0

step 6 add 1 to i, effectivly moving one column to the left.

step 7 set (c-sub(m)) to the value of carry

step 8 print out the final answer,(c-sub(m)),(c-sub(m-1))
....(c-sub(m-1))

step 9 stop
=================================================

thanks!

-t

Reply via email to