Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
The greatest common divisor of two numbers
#3
(11-04-2024, 10:16 PM)bplus Wrote: Hi Petr,

There are much simpler ways to do GCD:
https://rosettacode.org/wiki/Greatest_co...isor#BASIC

my favorite:
Code: (Select All)
_Title "GCD = Greatest Common Denominator" ' b+ 2020-05-21 from SB

While 1
    Input "enter a, b or 0 to quit "; a, b
    If a <> 0 And b <> 0 Then Print GCD(a, b) Else End
Wend

Function GCD (a As _Integer64, b As _Integer64)
    While a <> 0 And b <> 0
        If a > b Then a = a Mod b Else b = b Mod a
    Wend
    GCD = a + b
End Function

I just came and looking. Well, that's a beautiful example of how to do the same thing easily or complicatedly. And me (traditionally) chose the harder way Smile Thanks for your version, BPlus.  Big Grin


Reply


Messages In This Thread
RE: The greatest common divisor of two numbers - by Petr - 11-05-2024, 01:39 PM



Users browsing this thread: 1 Guest(s)