Skip to content

Add C# to EuclideanAlgorithmPage #7

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 16, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 50 additions & 0 deletions chapters/fundamental_algorithms/euclidean_algorithm/euclidean.md
Original file line number Diff line number Diff line change
Expand Up @@ -227,3 +227,53 @@ def euclid_sub(a, b):
print euclid_mod(64 * 67, 64 * 81)
print euclid_sub(128 * 12, 128 * 77)
```

### C#

```cs
// submitted by Julian Schacher‏
using System;

namespace Euclidean_Algorithm
{
class Program
{
static void Main(string[] args)
{
int check = Algorithms.EuclidMod(64 * 67, 64 * 81);
int check2 = Algorithms.EuclidSub(128 * 12, 128 * 77);

Console.WriteLine(check);
Console.WriteLine(check2);
}
}

public static class Algorithms
{
public static int EuclidSub(int a, int b)
{
while (a != b)
{
if (a > b)
a = a - b;
else
b = b - a;
}

return a;
}

public static int EuclidMod(int a, int b)
{
while (b != 0)
{
var temp = b;
b = a % b;
a = temp;
}

return a;
}
}
}
```