forked from 14visheshjain/DataStructure-Algorithm-in-java
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathhcf.java
More file actions
30 lines (26 loc) · 605 Bytes
/
hcf.java
File metadata and controls
30 lines (26 loc) · 605 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
// Author: Vishesh Jain
package first;
import java.util.Scanner;
public class hcf {
public static void main(String[] args) {
System.out.println("enter two numbers");
Scanner s = new Scanner(System.in);
// int n1=s.nextInt();
// int n2=s.nextInt();
// int i=1,hcf=1;
// while(i<=(n1) && i<=(n2)) {
// if(n1%i==0 && n2%i==0)
// hcf=i;
// i++;}
//System.out.println(hcf);
int divisor = s.nextInt();
int divident = s.nextInt();
int rem;
while (divident % divisor != 0) {
rem = divident % divisor;
divident = divisor;
divisor = rem;
}
System.out.println(divisor);
}
}