You are building an arithmetic tutor to help elementary-school
children learn longhand multiplication and division. As part
of the tutor, you need two functions, lmult
and ldiv, that output answers to arithmetic questions
in longhand.
lmult, to display the
longhand multiplication of two nonnegative integers.
For example, if you type
> (lmult 1234 567)
you should see the output
1234 567 ------ 8638 74040 617000 ------ 699678Similarly, if you type
> (lmult 567 1234)
you should see
567 1234 ------ 2268 17010 113400 567000 ------ 699678The output of your lmult function should look EXACTLY like the format shown above. It should work for arbitrarily large numbers.
ldiv to display the
longhand division of two nonnegative integers. Instead of computing
a terminating or repeating decimal, print out a remainder.
For example, if you type
> (ldiv 573 45)
you should see the output
12R33
----
45 | 573
45
---
123
90
---
33
As another example, if you type
> (ldiv 24 2)
you should see the output
12
---
2 | 24
2
--
4
4
-
0
Do not write R0 if the remainder is zero. Also, attempted division by zero
should result in an error message.
> (ldiv 402 2)outputs
201
----
2 | 402
4
--
0
0
--
2
2
-
0
> (ldiv 2 402)outputs
0R2
--
402 | 2
0
-
2
> (ldiv 4861 12)outputs
405R1
-----
12 | 4861
48
---
6
0
--
61
60
--
1
load, display, and
newline.load to load your file. Then I will call functions
lmult and ldiv from the command prompt.
You must use the function names lmult and ldiv.
lmult.lmult and ldiv, and a
design document in PDF format. Please
read the guidelines for the design document carefully.