From 6c83506cb44b1d20f66df404f0b6468b0e291b6b Mon Sep 17 00:00:00 2001 From: RossTheRoss Date: Tue, 25 Jun 2019 17:55:13 -0500 Subject: Do a thing: --- ee1301/wk3/lab3/gcd.cpp | 72 ++++++++++++++++++++++++------------------------- 1 file changed, 36 insertions(+), 36 deletions(-) (limited to 'ee1301/wk3/lab3/gcd.cpp') diff --git a/ee1301/wk3/lab3/gcd.cpp b/ee1301/wk3/lab3/gcd.cpp index e9c1801..4e127d9 100644 --- a/ee1301/wk3/lab3/gcd.cpp +++ b/ee1301/wk3/lab3/gcd.cpp @@ -1,36 +1,36 @@ -#include -#include -using namespace std; - -int GCD(int a, int b) { - int gcd=1; - 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); - while (gcd!=0) { - return GCD(b,gcd); - } - return b; - -} -int main () { - int a=0, b=0; - char cont; - do { - cout << "enter two integer values: "; - cin >> a >> b; - cout << "greatest common divisor is: " << GCD(a,b) << endl; - cout << "continue? (y/n): "; - cin >> cont; - cout << endl; - } while (cont!='n'); - -} +#include +#include +using namespace std; + +int GCD(int a, int b) { + int gcd=1; + 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); + while (gcd!=0) { + return GCD(b,gcd); + } + return b; + +} +int main () { + int a=0, b=0; + char cont; + do { + cout << "enter two integer values: "; + cin >> a >> b; + cout << "greatest common divisor is: " << GCD(a,b) << endl; + cout << "continue? (y/n): "; + cin >> cont; + cout << endl; + } while (cont!='n'); + +} -- cgit v1.2.3