Recursive function to return gcd of a and b
| 3 | using namespace std; |
| 4 | // Recursive function to return gcd of a and b |
| 5 | int 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 |
| 24 | int main() |