Browse Source

Add gcd.cpp

i0Ek3 1 year ago
parent
commit
090ca36070
1 changed files with 19 additions and 0 deletions
  1. 19
    0
      Algorithms/gcd.cpp

+ 19
- 0
Algorithms/gcd.cpp View File

@@ -0,0 +1,19 @@
1
+#include <iostream>
2
+
3
+long gcd(long a, long b)
4
+{
5
+    if (b == 0) {
6
+        return a;
7
+    }
8
+    int r = a % b;
9
+    return gcd(b, r);
10
+}
11
+
12
+int main()
13
+{
14
+    long n, m;
15
+    scanf("%ld%ld", &n, &m);
16
+    std::cout << "gcd is: " <<  gcd(n, m) << std::endl;
17
+    return 0;
18
+}
19
+

Loading…
Cancel
Save