How to resolve the algorithm Ethiopian multiplication step by step in the ZX Spectrum Basic programming language

Published on 12 May 2024 09:40 PM

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

Source code in the zx programming language

10 DEF FN e(a)=a-INT (a/2)*2-1
20 DEF FN h(a)=INT (a/2)
30 DEF FN d(a)=2*a
40 LET x=17: LET y=34: LET tot=0
50 IF x<1 THEN GO TO 100
60 PRINT x;TAB (4);
70 IF FN e(x)=0 THEN LET tot=tot+y: PRINT y: GO TO 90
80 PRINT "---"
90 LET x=FN h(x): LET y=FN d(y): GO TO 50
100 PRINT TAB (4);"===",TAB (4);tot

  

You may also check:How to resolve the algorithm Symmetric difference step by step in the ALGOL 68 programming language
You may also check:How to resolve the algorithm Happy numbers step by step in the C# programming language
You may also check:How to resolve the algorithm Hello world/Graphical step by step in the Prolog programming language
You may also check:How to resolve the algorithm Continued fraction step by step in the Chapel programming language
You may also check:How to resolve the algorithm Deceptive numbers step by step in the J programming language