Problem # 23 : Russian Peasants
The Russian peasants had an interesting way of doing multiplication of (not very large) integers. This method can be illustrated by the following example :
If 17 and 19 are to be multiplied they are put at the top of two columns
17 |
19 |
17 |
19 |
|
8 |
38 |
|
4 |
76 |
|
2 |
152 |
|
1 |
304 |
17 |
19 |
|
8 |
38 |
|
4 |
76 |
|
2 |
152 |
|
1 |
304 |
Write a procedure MULTIPLY(M N) which multiplies M and N using this method and prints each step on a cleared screen. (The values of M and N will not exceed 99)
Sample Output
MULTIPLY(79
46) should generate the following output :
79 |
46 |
|
39 |
92 |
|
19 |
184 |
|
9 |
368 |
|
4 |
736 |
|
2 |
1472 |
|
1 |
2944 |
|
--------------- |
||
3634 |
||
--------------- |
![]() |