Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 0cf2268

Browse filesBrowse files
Add lcm also along with gcd
Lcm can be very easily obtained by simple equation. n1*n2 = gcd*lcm
1 parent 04003e3 commit 0cf2268
Copy full SHA for 0cf2268

File tree

Expand file treeCollapse file tree

1 file changed

+10
-3
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

1 file changed

+10
-3
lines changed
Open diff view settings
Collapse file

‎gcd.java‎

Copy file name to clipboardExpand all lines: gcd.java
+10-3Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
public class gcd
1+
public class gcdAndLcm
22
{
33
// Recursive function to return gcd of a and b
44
static int gcd(int a, int b)
@@ -18,16 +18,23 @@ static int gcd(int a, int b)
1818
return gcd(a-b, b);
1919
return gcd(a, b-a);
2020
}
21+
22+
static int lcm(int a, int b)
23+
{
24+
return ((a*b)/gcd(a, b));
25+
}
2126

2227
// Driver method
2328
public static void main(String[] args)
2429
{
2530

2631
System.out.println(gcd(40,5));
27-
System.out.println(gcd(48,56));
32+
System.out.println(gcd(48,56));
33+
System.out.println(lcm(40,5));
34+
System.out.println(lcm(48,56));
2835

2936

3037

31-
}
38+
}
3239

3340
}

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.