Login
|
Signup
langref.org
-
fsharp
and
erlang
add..
all
clojure
cpp
csharp
fantom
go
groovy
haskell
java
ocaml
perl
php
python
ruby
scala
Home
All
Solved
Unsolved
Strings
Numbers
Regex
Lists
Maps
Structure
Files
Dates
OOP
Networking
XML
Algorithms
Misc
Parallel
View Problem
Algorithms
Arithmetic
Greatest Common Divisor
Find the largest positive integer that divides two given numbers without a remainder. For example, the GCD of 8 and 12 is 4.
fsharp
let rec gcd x y =
if y = 0 then x
else gcd y (x % y)
let rec gcd x y =
if y = 0 then x
else gcd y (x % y)
erlang
-module(gcd).
-export([gcd/2]).
gcd(A, 0) -> A;
gcd(A, B) -> gcd(B, A rem B).
-module(gcd).
-export([gcd/2]).
gcd(A, 0) -> A;
gcd(A, B) -> gcd(B, A rem B).
Submit a new solution for
fsharp
or
erlang
There are 15 other solutions in
additional
languages (
clojure
,
cpp
,
csharp
,
fantom
...)