How to resolve the algorithm Ethiopian multiplication step by step in the ActionScript programming language
Published on 12 May 2024 09:40 PM
How to resolve the algorithm Ethiopian multiplication step by step in the ActionScript 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 ActionScript programming language
Source code in the actionscript programming language
function Divide(a:Number):Number {
return ((a-(a%2))/2);
}
function Multiply(a:Number):Number {
return (a *= 2);
}
function isEven(a:Number):Boolean {
if (a%2 == 0) {
return (true);
} else {
return (false);
}
}
function Ethiopian(left:Number, right:Number) {
var r:Number = 0;
trace(left+" "+right);
while (left != 1) {
var State:String = "Keep";
if (isEven(Divide(left))) {
State = "Strike";
}
trace(Divide(left)+" "+Multiply(right)+" "+State);
left = Divide(left);
right = Multiply(right);
if (State == "Keep") {
r += right;
}
}
trace("="+" "+r);
}
}
You may also check:How to resolve the algorithm McNuggets problem step by step in the BASIC programming language
You may also check:How to resolve the algorithm Logistic curve fitting in epidemiology step by step in the Perl programming language
You may also check:How to resolve the algorithm Filter step by step in the Fantom programming language
You may also check:How to resolve the algorithm Spinning rod animation/Text step by step in the NS-HUBASIC programming language
You may also check:How to resolve the algorithm Grayscale image step by step in the Fortran programming language