We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
2 parents 1071da1 + 57c70cc commit 0a60235Copy full SHA for 0a60235
gcd.c
@@ -0,0 +1,34 @@
1
+#include <stdio.h>
2
+#include <stdlib.h>
3
+
4
+long long get_gcd_recursive(long long a, long long b)
5
+{
6
+ if (a == 0) {
7
+ return b;
8
+ } else if (b == 0) {
9
+ return a;
10
+ }
11
12
+ /* Swap the two numbers */
13
+ if (b > a) {
14
+ a = a - b;
15
+ b = a + b;
16
+ a = b - a;
17
18
19
+ long long remainder = a % b;
20
+ if (remainder == 0) {
21
22
23
24
+ return get_gcd_recursive(b, remainder);
25
+}
26
27
+int main()
28
29
+ long long a = 0;
30
+ long long b = 0;
31
+ scanf("%lld", &a);
32
+ scanf("%lld", &b);
33
+ printf("%lld", get_gcd_recursive(a, b));
34
0 commit comments