August 23, 2024

P32 - Determine the greatest common divisor of two positive integer numbers.

Use Euclid's algorithm.

> gcd(36, 63)
  res0: Int = 9

erlang

% Determine the greatest common divisor of two positive integer numbers.

-module(p32).
-export([gcd/2]).


gcd(0, B) ->
    B;

gcd(A, 0) ->
    A;

gcd(A, B) -> 
    gcd(B, A rem B).
Be first to comment
Leave a reply