Entry
BBCBASIC: Windows: Mathematics: How to calculate the greatest common divisor? Iterative
Apr 26th, 2006 11:35
Knud van Eeden,
REM library: greatest: common: divisor: iterative
(filenamemacro=commgrdi.bbc) [kn, amv, we, 26-04-2006 18:19:06]
DEF FNGreatestCommonDivisorIterative( number1I%, number2I% )
REM e.g. REM goal: determine of 2 numbers
REM e.g. REM
REM e.g. REM The greatest common divisor
REM e.g. :
REM e.g. PRINT FNGreatestCommonDivisorIterative( 10, 20 ) : REM gives
10
REM e.g. PRINT FNGreatestCommonDivisorIterative( 2, 13 ) : REM gives 1
REM e.g. PRINT FNGreatestCommonDivisorIterative( 1231232, 1234 ) :
REM gives 2
REM e.g. END
REM e.g. :
REM e.g. :
REM e.g. :
LOCAL stopB%
LOCAL tempI%
REPEAT
stopB% = ( number2I% = 0 )
IF NOT stopB% THEN tempI% = number2I% : number2I% = number1I% MOD
number2I% : number1I% = tempI%
UNTIL stopB%
= number1I%
: