forked from iiitv/algos
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEuclideanGCD.cs
More file actions
35 lines (32 loc) · 781 Bytes
/
EuclideanGCD.cs
File metadata and controls
35 lines (32 loc) · 781 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
using System;
public class EuclideanGCD
{
public static long euclidean_gcd(long a, long b)
{
if(a == 0)
{
return (b);
}
else
{
return euclidean_gcd(b % a, a);
}
}
public static long euclidean_gcd_iterative(long a, long b)
{
while (b != 0)
{
long temp = b;
b = a % b;
a = temp;
}
return a;
}
public static void Main()
{
int a = 9000, b = 145685;
Console.WriteLine("GCD of " + a + " and " + b + " by recursive is : " + euclidean_gcd(a, b));
Console.WriteLine("GCD of " + a + " and " + b + " by iterative is : " + euclidean_gcd_iterative(a, b));
Console.WriteLine("");
}
}