Skip to content

Commit ea1b922

Browse files
authored
Merge pull request #7 from julianschacherpp/patch-1
Add C# to EuclideanAlgorithmPage
2 parents 3621c8e + f6a8103 commit ea1b922

File tree

1 file changed

+50
-0
lines changed
  • chapters/fundamental_algorithms/euclidean_algorithm

1 file changed

+50
-0
lines changed

chapters/fundamental_algorithms/euclidean_algorithm/euclidean.md

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,3 +227,53 @@ def euclid_sub(a, b):
227227
print euclid_mod(64 * 67, 64 * 81)
228228
print euclid_sub(128 * 12, 128 * 77)
229229
```
230+
231+
### C#
232+
233+
```cs
234+
// submitted by Julian Schacher‏
235+
using System;
236+
237+
namespace Euclidean_Algorithm
238+
{
239+
class Program
240+
{
241+
static void Main(string[] args)
242+
{
243+
int check = Algorithms.EuclidMod(64 * 67, 64 * 81);
244+
int check2 = Algorithms.EuclidSub(128 * 12, 128 * 77);
245+
246+
Console.WriteLine(check);
247+
Console.WriteLine(check2);
248+
}
249+
}
250+
251+
public static class Algorithms
252+
{
253+
public static int EuclidSub(int a, int b)
254+
{
255+
while (a != b)
256+
{
257+
if (a > b)
258+
a = a - b;
259+
else
260+
b = b - a;
261+
}
262+
263+
return a;
264+
}
265+
266+
public static int EuclidMod(int a, int b)
267+
{
268+
while (b != 0)
269+
{
270+
var temp = b;
271+
b = a % b;
272+
a = temp;
273+
}
274+
275+
return a;
276+
}
277+
}
278+
}
279+
```

0 commit comments

Comments
 (0)