How to resolve the algorithm Ethiopian multiplication step by step in the M2000 Interpreter programming language
Published on 12 May 2024 09:40 PM
How to resolve the algorithm Ethiopian multiplication step by step in the M2000 Interpreter programming language
Table of Contents
Problem Statement
Ethiopian multiplication is a method of multiplying integers using only addition, doubling, and halving.
Method:
For example: 17 × 34 Halving the first column: Doubling the second column: Strike-out rows whose first cell is even: Sum the remaining numbers in the right-hand column: So 17 multiplied by 34, by the Ethiopian method is 578.
The task is to define three named functions/methods/procedures/subroutines:
Use these functions to create a function that does Ethiopian multiplication.
Let's start with the solution:
Step by Step solution about How to resolve the algorithm Ethiopian multiplication step by step in the M2000 Interpreter programming language
Source code in the m2000 programming language
Module EthiopianMultiplication{
Form 60, 25
Const Center=2, ColumnWith=12
Report Center,"Ethiopian Method of Multiplication"
// using decimals as unsigned integers
Def Decimal leftval, rightval, sum
(leftval, rightval)=(random(1, 65535), random(1, 65536))
Print $( , ColumnWith), "Target:", leftval*rightval,
Hex leftval*rightval
sum=0
if @IsEven(leftval) Else sum+=rightval
Print leftval, rightval,
Hex leftval, rightval
while leftval>1
leftval=@halveInt(leftval)
rightval=@DoubleInt(rightval)
Print leftval, rightval,
Hex leftval, rightval
if @IsEven(leftval) Else sum+=rightval
End while
Print "", sum
Hex "", sum
Function HalveInt(i)
=Binary.Shift(i,-1)
End Function
Function DoubleInt(i)
=Binary.Shift(i,1)
End Function
Function IsEven(i)
=Binary.And(i, 1)=0
End Function
}
EthiopianMultiplication
You may also check:How to resolve the algorithm Rot-13 step by step in the VBScript programming language
You may also check:How to resolve the algorithm String matching step by step in the VBA programming language
You may also check:How to resolve the algorithm MD4 step by step in the Lasso programming language
You may also check:How to resolve the algorithm A+B step by step in the Racket programming language
You may also check:How to resolve the algorithm Babbage problem step by step in the SequenceL programming language