Website Summary Files Commits Branches @commit @diff @stats
path: root / Sem. 03 / example 1 - gcd (naive).cpp
diff options
context:
space:
mode:
Commitd7c6ef7130288c7a842184e9e280c8a07abfbc9c (patch)
Author
 angeld55 <angel_dimitriev@abv.bg>
2021-10-21 21:12:50 +0300
Committer
 angeld55 <angel_dimitriev@abv.bg>
2021-10-21 21:12:50 +0300
Files17f5ed73cc77d86e3c6d469887ff89ff87e61a2e /Sem. 03/example 1 - gcd (naive).cpp
Introduction_to_programming_FMI-d7c6ef7130288c7a842184e9e280c8a07abfbc9c.tar
Introduction_to_programming_FMI-d7c6ef7130288c7a842184e9e280c8a07abfbc9c.tar.gz
Introduction_to_programming_FMI-d7c6ef7130288c7a842184e9e280c8a07abfbc9c.zip
Parent99d2566b60caa52133d431869e57cdb7a7279b6d (diff)
sem 3
1 files changed, 21 insertions, 0 deletions
-rw-r--r--Sem. 03/example 1 - gcd (naive).cpp21
diff --git a/Sem. 03/example 1 - gcd (naive).cpp b/Sem. 03/example 1 - gcd (naive).cpp
new file mode 100644
index 0000000..65d82d4
--- /dev/null
+++ b/Sem. 03/example 1 - gcd (naive).cpp
@@ -0,0 +1,21 @@
+#include <iostream>
+
+using namespace std;
+int main()
+{
+ int n, k;
+ cin >> n >> k;
+
+ int min = n < k ? n : k;
+ int gcd = 1;
+ while (min >= 1)
+ {
+ if (n % min == 0 && k % min == 0)
+ {
+ gcd = min;
+ }
+ min--;
+ }
+
+ cout << gcd << endl;
+} \ No newline at end of file