forked from sukritishah15/DS-Algo-Point
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathEuclid_GCD.c
36 lines (29 loc) · 833 Bytes
/
Euclid_GCD.c
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
// Program to find GCD of two numbers using Euclidean GCD algorithm
// This program returns GCD in O(log(N)) time.
#include <stdio.h>
int euclids_gcd(int a,int b) // recursive function
{
if(b == 0)
{
return a;
}
return euclids_gcd(b, a%b);
}
int print_gcd(int a,int b)
{
int ans = euclids_gcd(a,b);
printf("GCD of above numbers is %d",ans);
}
int main()
{
int a,b;
printf("Enter 2 number's for which GCD is required \n");
scanf("%d %d",&a,&b);
print_gcd(a,b);
return 0;
}
/*
Enter 2 number's for which GCD is required
4 8
GCD of above numbers is 4
*/