MCPcopy Create free account
hub / github.com/codemistic/Data-Structures-and-Algorithms / gcd

Function gcd

CPP/recursion/GCD_Rec.cpp:5–21  ·  view source on GitHub ↗

Recursive function to return gcd of a and b

Source from the content-addressed store, hash-verified

3using namespace std;
4// Recursive function to return gcd of a and b
5int gcd(int a, int b)
6{
7 // Everything divides 0
8 if (a == 0)
9 return b;
10 if (b == 0)
11 return a;
12
13 // base case
14 if (a == b)
15 return a;
16
17 // a is greater
18 if (a > b)
19 return gcd(a-b, b);
20 return gcd(a, b-a);
21}
22
23// Driver program to test above function
24int main()

Callers 1

mainFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected