-
Notifications
You must be signed in to change notification settings - Fork 42
/
Copy pathHcfLcm.java
54 lines (54 loc) · 982 Bytes
/
HcfLcm.java
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
import java.util.Scanner;
class HcfLcm
{
int a,b,hcf,lcm;
HcfLcm()
{
a=0;
b=0;
hcf=1;
lcm=0;
}
void getdata()
{
Scanner sc=new Scanner(System.in);
System.out.println("Enter the first number");
a=sc.nextInt();
System.out.println("Enter the second number");
b=sc.nextInt();
}
void change()
{
if(a>b)
{
a=b;
b=a;
}
}
int rechcf(int p, int q)
{
if(p==0)
return q;
else
return rechcf(q%p,p);
}
int fn_lcm(int a, int b,int c)
{
return (a*b)/c;
}
void result()
{
hcf= rechcf(a,b);
lcm=fn_lcm(a,b,hcf);
System.out.println("HCF of these numbers "+hcf);
System.out.println("LCM of these mumbers "+lcm);
}
}
/*OUTPUT
* Enter the first number
4
Enter the second number
6
HCF of these numbers 2
LCM of these mumbers 12
*/