File tree Expand file tree Collapse file tree 1 file changed +15
-1
lines changed Expand file tree Collapse file tree 1 file changed +15
-1
lines changed Original file line number Diff line number Diff line change 2
2
using namespace std ;
3
3
4
4
/* LCM * HCf = a * b */
5
-
5
+ /* function to find LCM */
6
6
int LCM (int a, int b, int gcd) {
7
+ /* relation between lcm and hcf/gcd */
7
8
int lcm = (a * b) / gcd;
8
9
return lcm;
9
10
}
10
11
12
+ /* function to find gcd */
11
13
int GCD (int a, int b) {
14
+ /* if a = 0 then b is gcd */
12
15
if (a == 0 ) {
13
16
return b;
14
17
}
18
+
19
+ /* if b = 0 then a is gcd */
15
20
if (b == 0 ) {
16
21
return a;
17
22
}
18
23
24
+ /* subtracting greater number from lower
25
+ unless they both are equal
26
+ once they are equal return any number a or b*/
19
27
while (a != b) {
28
+ /* if a is greater subrating b from it */
20
29
if (a > b) {
21
30
a = a - b;
22
31
} else {
32
+ /* if b is greater subrating a from it */
23
33
b = b - a;
24
34
}
25
35
}
36
+ /* returning gcd */
26
37
return a;
27
38
}
28
39
@@ -33,10 +44,13 @@ int main() {
33
44
cout << " Enter B: " ;
34
45
cin >> b;
35
46
47
+ /* calling gcd funtion */
36
48
int gcd = GCD (a, b);
37
49
cout << gcd << endl;
38
50
51
+ /* calling lcm function */
39
52
int lcm = LCM (a, b, gcd);
40
53
cout << lcm << endl;
54
+
41
55
return 0 ;
42
56
}
You can’t perform that action at this time.
0 commit comments