summaryrefslogtreecommitdiff
path: root/Q3a.cpp
diff options
context:
space:
mode:
authorMichael Abed <michaelabed@gmail.com>2012-03-02 14:19:26 -0500
committerMichael Abed <michaelabed@gmail.com>2012-03-02 14:19:26 -0500
commit973562e3bbffbe2502649ce30d55e7cc6cbc6c3c (patch)
treed6fe33a799e9ca0034e9e98b6b155b0706937f83 /Q3a.cpp
parentc2391ab3040f0ce641eb77b2fe5a693b9f6e2444 (diff)
downloadec327-lab2-973562e3bbffbe2502649ce30d55e7cc6cbc6c3c.tar.gz
ec327-lab2-973562e3bbffbe2502649ce30d55e7cc6cbc6c3c.tar.bz2
ec327-lab2-973562e3bbffbe2502649ce30d55e7cc6cbc6c3c.zip
i did things
Diffstat (limited to 'Q3a.cpp')
-rw-r--r--Q3a.cpp36
1 files changed, 36 insertions, 0 deletions
diff --git a/Q3a.cpp b/Q3a.cpp
new file mode 100644
index 0000000..cbe9023
--- /dev/null
+++ b/Q3a.cpp
@@ -0,0 +1,36 @@
+
+#include <iostream>
+
+using namespace std;
+
+int gcd(int m, int n);
+
+int gcd(int m, int n)
+{
+ if (m <= 0 || n <= 0)
+ return 0;
+
+ if (m % n == 0)
+ return n;
+ else
+ return gcd(n, m%n);
+}
+
+int main(int argc, const char *argv[])
+{
+ int m, n;
+ int result;
+ cout << "Enter 2 numbers to calculate the greatest common divisor (0 to quit)" << endl;
+ do {
+ cout << ">> ";
+ cin >> m >> n;
+ if (m <= 0 || n <= 0) {
+ cout << "Please input positive numbers (0 to quit)" << endl;
+ } else {
+ result = gcd(m, n);
+ cout << "gcd(" << m << ", " << n << ") = " << result << endl;
+ }
+ } while (m != 0 || n != 0);
+
+ return 0;
+}