diff options
Diffstat (limited to '')
-rw-r--r-- | ee1301/wk3/lab3/gcd.cpp | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/ee1301/wk3/lab3/gcd.cpp b/ee1301/wk3/lab3/gcd.cpp new file mode 100644 index 0000000..435fd07 --- /dev/null +++ b/ee1301/wk3/lab3/gcd.cpp @@ -0,0 +1,25 @@ +#include <iostream> +#include <cmath> +using namespace std; + +int GCD(int a, int b) { + int gcd=0; + a=abs(a); b=abs(b); + if (a>b) { + //do nothing + } else { + if (b>a) { + int foo=a; a=b; b=foo; + } else { + return 1; + } + } + gcd=(a/b)+(a%b); + return gcd; +} +int main () { + int a=0, b=0; + cout << "Enter two integers: "; + cin >> a, b; + cout << GCD(a,b) << endl; +} |