forked from jainaman224/Algo_Ds_Notes
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathExtended_Euclidean_Algorithm.cs
More file actions
38 lines (34 loc) · 901 Bytes
/
Extended_Euclidean_Algorithm.cs
File metadata and controls
38 lines (34 loc) · 901 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
using System;
namespace Extended_Euclidean_GCD
{
class Program
{
public static int gcdFunction(int a, int b, int x, int y)
{
if (a == 0)
{
x = 0;
y = 0;
return b;
}
int x1 = 0;
int y1 = 0;
int gcd = gcdFunction(b % a, a, x1, y1);
x = y1 - (b / a) * x1;
y = x1;
return gcd;
}
public static void Main(String[] args)
{
int a = 98;
int b = 21;
int x = 0;
int y = 0;
Console.WriteLine("GCD of numbers " + Convert.ToString(a) + " and " + Convert.ToString(b) + " is " + Convert.ToString(gcdFunction(a, b, x, y)));
Console.WriteLine();
Console.ReadLine();
}
}
}
// Output
// GCD of numbers 98 and 21 is 7