summaryrefslogtreecommitdiffstats
path: root/01-algorithmic_toolbox/01-intro/03-gcd/gcd.cpp
diff options
context:
space:
mode:
authorJérémy Zurcher <jeremy@asynk.ch>2016-11-13 19:00:06 +0100
committerJérémy Zurcher <jeremy@asynk.ch>2016-11-13 19:00:06 +0100
commit13eab863735725f9a02cd4ae0b1c25725cc27569 (patch)
tree20be81c90e02f3a5dee54392435bb7baf8e7b571 /01-algorithmic_toolbox/01-intro/03-gcd/gcd.cpp
downloadcoursera-13eab863735725f9a02cd4ae0b1c25725cc27569.zip
coursera-13eab863735725f9a02cd4ae0b1c25725cc27569.tar.gz
Algorithms : add 01-algorithmic_toolbox 01-intro
Diffstat (limited to '01-algorithmic_toolbox/01-intro/03-gcd/gcd.cpp')
-rw-r--r--01-algorithmic_toolbox/01-intro/03-gcd/gcd.cpp21
1 files changed, 21 insertions, 0 deletions
diff --git a/01-algorithmic_toolbox/01-intro/03-gcd/gcd.cpp b/01-algorithmic_toolbox/01-intro/03-gcd/gcd.cpp
new file mode 100644
index 0000000..f723be2
--- /dev/null
+++ b/01-algorithmic_toolbox/01-intro/03-gcd/gcd.cpp
@@ -0,0 +1,21 @@
+#include <iostream>
+
+int gcd(int a, int b) {
+ //write your code here
+ int current_gcd = 1;
+ for (int d = 2; d <= a && d <= b; d++) {
+ if (a % d == 0 && b % d == 0) {
+ if (d > current_gcd) {
+ current_gcd = d;
+ }
+ }
+ }
+ return current_gcd;
+}
+
+int main() {
+ int a, b;
+ std::cin >> a >> b;
+ std::cout << gcd(a, b) << std::endl;
+ return 0;
+}