We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent bc304c5 commit 99e6b6aCopy full SHA for 99e6b6a
gcd/gcd.java
@@ -0,0 +1,27 @@
1
+// Java program to find factorial of given number
2
+class gcd
3
+{
4
+ // Recursive function to return gcd of a and b
5
+ static int gcd(int a, int b)
6
+ {
7
+ // Everything divides 0
8
+ if (a == 0 || b == 0)
9
+ return 0;
10
+
11
+ // base case
12
+ if (a == b)
13
+ return a;
14
15
+ // a is greater
16
+ if (a > b)
17
+ return gcd(a-b, b);
18
+ return gcd(a, b-a);
19
+ }
20
21
+ // Driver method
22
+ public static void main(String[] args)
23
24
+ int a = 98, b = 56;
25
+ System.out.println("GCD of " + a +" and " + b + " is " + gcd(a, b));
26
27
+}
0 commit comments