Renewed Structure
This commit is contained in:
20
Algorithm/Recursion/P29_23_GCD.cpp
Normal file
20
Algorithm/Recursion/P29_23_GCD.cpp
Normal file
@@ -0,0 +1,20 @@
|
||||
#include <iostream>
|
||||
#include <cmath>
|
||||
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;
|
||||
}
|
Reference in New Issue
Block a user