forked from Annex5061/java-algorithms
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGcd.java
More file actions
33 lines (29 loc) · 687 Bytes
/
Gcd.java
File metadata and controls
33 lines (29 loc) · 687 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
27
28
29
30
31
32
33
import java.util.*;
class Gcd
{
public static int gcd(int n1,int n2)
{
while(n1!=n2)
{
if(n1>n2)
{
n1=n1-n2;
}
else
{
n2=n2-n1;
}
}
return n1;
}
public static void main(String args[])
{
int n1,n2;
Scanner Sc = new Scanner(System.in);
System.out.print("enter n1:");
n1=Sc.nextInt();
System.out.print("enter n2:");
n2=Sc.nextInt();
System.out.println("gcd of "+n1+" and "+n2+" is "+gcd(n1,n2));
}
}