Skip to content
Open
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Create eucledian.c
  • Loading branch information
rohitsekar1996 authored Oct 2, 2018
commit 99410a98b7fdee7e3d9a8594b72c52ba1c9c269e
30 changes: 30 additions & 0 deletions Algorithms/eucledian.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@

// Euclidean Algorithm
#include <stdio.h>

// C function for extended Euclidean Algorithm
int gcdExtended(int a, int b, int *x, int *y)
{
// Base Case
if (a == 0)
{
*x = 0;
*y = 1;
return b;
}

int x1, y1; // To store results of recursive call
int gcd = gcdExtended(b%a, a, &x1, &y1);
*x = y1 - (b/a) * x1;
*y = x1;

return gcd;
}
int main()
{
int x, y;
int a = 35, b = 15;
int g = gcdExtended(a, b, &x, &y);
printf("gcd(%d, %d) = %d", a, b, g);
return 0;
}