1// C++ program to find GCD of two numbers
2#include <iostream>
3using namespace std;
4// Recursive function to return gcd of a and b
5int gcd(int a, int b)
6{
7 if (b == 0)
8 return a;
9 return gcd(b, a % b);
10
11}
12
13// Driver program to test above function
14int main()
15{
16 int a = 98, b = 56;
17 cout<<"GCD of "<<a<<" and "<<b<<" is "<<gcd(a, b);
18 return 0;
19}
20
1int gcd(int a, int b)
2{
3 // Everything divides 0
4 if (a == 0)
5 return b;
6 if (b == 0)
7 return a;
8 // base case
9 if (a == b)
10 return a;
11 // a is greater
12 if (a > b)
13 return gcd(a-b, b);
14 return gcd(a, b-a);
15}
1#include<bits/stdc++.h>
2using namespace std;
3long long UCLN(long long a,long long b)
4{
5 long long r;
6 while (b!=0)
7 {
8 r=a%b;
9 a=b;
10 b=r;
11 }
12 return a;
13}
14
15
16int main()
17{
18 long long a, b;
19 cout<< "enter: ";
20 cin>> a;
21 cout<< "enter: ";
22 cin >>b;
23 cout<<UCLN(a,b)<<endl;
24 return 0;
25}