Skip to content

Commit 5d2fad3

Browse files
authored
Merge pull request ephremdeme#138 from SekharV/master
1. Implementation for GCD and LCM in C#
2 parents 759fdc0 + 783c117 commit 5d2fad3

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

Mathematics/GCD/Mathematics.cs

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
using System;
2+
3+
namespace TestMath
4+
{
5+
public static class Mathematics
6+
{
7+
/// <summary>
8+
/// Calcualtes Greatest Common Divisor of given 2 integers
9+
/// </summary>
10+
/// <param name="a"></param>
11+
/// <param name="b"></param>
12+
/// <returns></returns>
13+
public static int GCD(int a,int b)
14+
{
15+
if (a % b == 0)
16+
{
17+
return b;
18+
}
19+
20+
return GCD(b, a % b);
21+
}
22+
23+
/// <summary>
24+
/// Calcualtes Least Common Multiple of given 2 integers
25+
/// </summary>
26+
/// <param name="a"></param>
27+
/// <param name="b"></param>
28+
/// <returns></returns>
29+
public static int LCM(int a, int b)
30+
{
31+
return Math.Min(a, b) * GCD(a, b);
32+
}
33+
}
34+
}

0 commit comments

Comments
 (0)