diff --git a/Recursion/P29_23_GCD.cpp b/Recursion/P29_23_GCD.cpp index 604782e..c14cf44 100644 --- a/Recursion/P29_23_GCD.cpp +++ b/Recursion/P29_23_GCD.cpp @@ -1 +1,20 @@ #include +#include +using namespace std; + +int gcd(int x, int y){ + x = abs(x); + y = abs(y); + if(y == 0) + return x; + if(y > 0) + return gcd(y, x % y); + return 0; +} + +int main(){ + cout << gcd(20 ,30) << endl; + cout << gcd(112, 42) << endl; + cout << gcd(-112,42) << endl; + return 0; +} diff --git a/Recursion/P29_23_GCD.exe b/Recursion/P29_23_GCD.exe new file mode 100644 index 0000000..5d8f6a3 Binary files /dev/null and b/Recursion/P29_23_GCD.exe differ diff --git a/Recursion/P29_24_checkfunc.cpp b/Recursion/P29_24_checkfunc.cpp new file mode 100644 index 0000000..843da0c --- /dev/null +++ b/Recursion/P29_24_checkfunc.cpp @@ -0,0 +1,33 @@ +/* +Request: Code a template module to check if x is in a[0:n-1] +*/ + +#include +#include +using namespace std; + +template +bool chk(T x, T* a, int n){ + if(n > 1 && x != a[n - 1]) + return chk(x,a,n-1); + if(n == 1 && x != a[0]) + return false; + return true; +} + +int main(){ + int a[] = {2,3,4,5,6,7,9}; + cout << chk(2,a,7) << " " << chk(1,a,7)< +bool chk(T x, T* a, int n) { + if (n <= 0) return false; + if (a[n - 1] == x) return true; + return chk(x, a, n - 1); +} +*/ diff --git a/Recursion/P29_24_checkfunc.exe b/Recursion/P29_24_checkfunc.exe new file mode 100644 index 0000000..adb0b3d Binary files /dev/null and b/Recursion/P29_24_checkfunc.exe differ