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;
3
4int gcd(int a,int b){
5 if(a==0){
6 return b;
7 }
8 if(b==0){
9 return a;
10 }
11
12 if(a==b){
13 return a;
14 }
15
16 int x=0;
17 int mx = INT_MIN;
18 int mi = min(a,b);
19 for(int i=2;i<=mi;i++){
20 if(a%i==0 and b%i==0){
21 mx = max(mx,i);
22 }
23 }
24
25 return mx;
26
27}
28
29int main() {
30 int a = 36;
31 int b = 60;
32 cout<<gcd(a,b);
33
34}
35