Website Summary Files Commits Branches @commit @diff @stats
path: root / Sem. 03 / example 2 - gcd (euclid).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 2 - gcd (euclid).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, 24 insertions, 0 deletions
-rw-r--r--Sem. 03/example 2 - gcd (euclid).cpp24
diff --git a/Sem. 03/example 2 - gcd (euclid).cpp b/Sem. 03/example 2 - gcd (euclid).cpp
new file mode 100644
index 0000000..4f2a97d
--- /dev/null
+++ b/Sem. 03/example 2 - gcd (euclid).cpp
@@ -0,0 +1,24 @@
+#include <iostream>
+
+using namespace std;
+int main()
+{
+ int n, k;
+ cin >> n >> k;
+
+ if (n < k) //swap
+ {
+ int temp = k;
+ n = k;
+ k = temp;
+ }
+
+ while (k != 0)
+ {
+ int mod = n % k;
+ n = k;
+ k = mod;
+ }
+
+ cout << n << endl;
+} \ No newline at end of file