diff --git a/Miscellaneous/GreatestCommonDivisor.cpp b/Miscellaneous/GreatestCommonDivisor.cpp new file mode 100644 index 0000000..199d518 --- /dev/null +++ b/Miscellaneous/GreatestCommonDivisor.cpp @@ -0,0 +1,29 @@ +#include +using namespace std; +// Recursive function to return gcd of a and b +int gcd(int a, int b) +{ + // Everything divides 0 + if (a == 0) + return b; + if (b == 0) + return a; + + // base case + if (a == b) + return a; + + // a is greater + if (a > b) + return gcd(a-b, b); + return gcd(a, b-a); +} + +// Driver program to test above function +int main() +{ + int a, b; + cin>>a>>b; + cout<<"GCD of "<