Login
|
Signup
langref.org
-
ruby
,
csharp
, and
erlang
add..
all
clojure
cpp
fantom
fsharp
go
groovy
haskell
java
ocaml
perl
php
python
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.
ruby
1.9.1
135.gcd(30)
# => 15
135.gcd(30)
# => 15
csharp
public static int gcd(int a, int b)
{
if (b == 0)
return a;
else
return gcd(b, a % b);
}
class SolutionXX
{
public static int gcd(int a, int b)
{
if (b == 0)
return a;
else
return gcd(b, a % b);
}
}
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
ruby
,
csharp
, or
erlang
There are 14 other solutions in
additional
languages (
clojure
,
cpp
,
fantom
,
fsharp
...)