How to resolve the algorithm Ethiopian multiplication step by step in the Action! programming language

Published on 12 May 2024 09:40 PM

How to resolve the algorithm Ethiopian multiplication step by step in the Action! 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 Action! programming language

Source code in the action! programming language

INT FUNC EthopianMult(INT a,b)
  INT res

  PrintF("Ethopian multiplication %I by %I:%E",a,b)
  res=0
  WHILE a>=1
  DO
    IF a MOD 2=0 THEN
      PrintF("%I %I strike%E",a,b)
    ELSE
      PrintF("%I %I keep%E",a,b)
      res==+b
    FI
    a==/2
    b==*2
  OD
RETURN (res)

PROC Main()
  INT res

  res=EthopianMult(17,34)
  PrintF("Result is %I",res)
RETURN

  

You may also check:How to resolve the algorithm Base64 decode data step by step in the Arturo programming language
You may also check:How to resolve the algorithm Longest increasing subsequence step by step in the Icon and Unicon programming language
You may also check:How to resolve the algorithm Simulate input/Keyboard step by step in the Go programming language
You may also check:How to resolve the algorithm Sequence of non-squares step by step in the REXX programming language
You may also check:How to resolve the algorithm Metered concurrency step by step in the Logtalk programming language