forked from nirala96/open_source_start
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGCD.java
More file actions
26 lines (23 loc) · 632 Bytes
/
GCD.java
File metadata and controls
26 lines (23 loc) · 632 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
/* Java program to find GCD of two numbers
using recursion*/
import java.util.Scanner;
class GCD
{
// Recursive function to return gcd of a and b
static int gcd(int a, int b)
{
if (b == 0)
return a;
return gcd(b, a % b);
}
// Driver code
public static void main(String[] args)
{Scanner sc = new Scanner(System.in);
System.out.print("Enter first number:");
int a = sc.nextInt();
System.out.print("Enter second number:");
int b = sc.nextInt();
System.out.println("GCD of " + a +" and " + b + " is " + gcd(a, b));
sc.close();
}
}