How to resolve the algorithm Ethiopian multiplication step by step in the Relation programming language
Published on 12 May 2024 09:40 PM
How to resolve the algorithm Ethiopian multiplication step by step in the Relation 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 Relation programming language
Source code in the relation programming language
function half(x)
set result = floor(x/2)
end function
function double(x)
set result = 2*x
end function
function even(x)
set result = (x/2 > floor(x/2))
end function
program ethiopian_mul(a,b)
relation first, second
while a >= 1
insert a, b
set a = half(a)
set b = double(b)
end while
extend third = even(first) * second
project third sum
end program
run ethiopian_mul(17,34)
print
You may also check:How to resolve the algorithm Move-to-front algorithm step by step in the jq programming language
You may also check:How to resolve the algorithm Semordnilap step by step in the Liberty BASIC programming language
You may also check:How to resolve the algorithm QR decomposition step by step in the Common Lisp programming language
You may also check:How to resolve the algorithm Strip whitespace from a string/Top and tail step by step in the COBOL programming language
You may also check:How to resolve the algorithm Julia set step by step in the zkl programming language