' From the Computer Mathematics Concepts text ' Mathematical Ideas, Ninth Edition, Section 4.2 ' Russian Peasant Method for Integer Multiplication ' Written by Michael L. Jones, M. S., Spring 2002 ' Suffolk County Community College, Brentwood, New York ' Plan of attack: Start with two integers, a and b. If a is odd, add b to ' the product; if b is even, do nothing. Take the integer part of a divided ' by 2, and double b. Repeat until a=0, and the product will have been ' accumulated. CLS INPUT "What is the first factor"; x INPUT "What is the second factor"; y PRINT a = x ' Copies of original values so we can check our product later b = y p = 0 ' Initialize product WHILE a > 0 ' We stop when a=0; a WHILE...WEND loop is efficient PRINT a, b, ' Print current a and b and stay on that line IF a MOD 2 = 0 GOTO 1 ' Skip the next steps for even a PRINT "*"; ' a is odd, so we mark b with an asterisk to indicate addend p = p + b ' Addend b is added to product 1 ' Line number for use with the GOTO above. do the following for any a PRINT ' End the printed line a = INT(a / 2) ' Take the integer part of a/2 b = b * 2 ' Double b WEND ' End of WHILE loop ' Print out results PRINT PRINT "The peasant method gives"; p PRINT PRINT "The actual product is"; x * y