-
-
Notifications
You must be signed in to change notification settings - Fork 358
Expand file tree
/
Copy pathEuclideanAlgorithm.cs
More file actions
41 lines (35 loc) · 833 Bytes
/
EuclideanAlgorithm.cs
File metadata and controls
41 lines (35 loc) · 833 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
36
37
38
39
40
41
// submitted by Julian Schacher (jspp)
using System;
namespace EuclideanAlgorithm
{
public class EuclideanAlgorithm
{
public int EuclidSub(int a, int b)
{
// Math.Abs for negative number support
a = Math.Abs(a);
b = Math.Abs(b);
while (a != b)
{
if (a > b)
a = a - b;
else
b = b - a;
}
return a;
}
public int EuclidMod(int a, int b)
{
// Math.Abs for negative number support
a = Math.Abs(a);
b = Math.Abs(b);
while (b != 0)
{
var temp = b;
b = a % b;
a = temp;
}
return a;
}
}
}