Skip to content
This repository has been archived by the owner on Jul 21, 2024. It is now read-only.

Commit

Permalink
Added the possibility to get the divisors of a specific number (#297)
Browse files Browse the repository at this point in the history
  • Loading branch information
lpeyr committed Feb 12, 2022
1 parent b41c055 commit 8dfbda3
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions LeoCorpLibrary/Extensions/IntExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
using System;
using System.Collections.Generic;

namespace LeoCorpLibrary.Extensions
{
Expand Down Expand Up @@ -166,5 +167,20 @@ public static double ConvertSizeUnitToPetabyte(this int i, UnitType unitType)
default: return i; // Convert and return value
}
}

public static int[] GetDivisors(this int number)
{
List<int> ds = new List<int>(); // Create a list

for (int i = 1; i <= number; i++)
{
if (number % i == 0) // Check if the number is a divisor
{
ds.Add(i); // Add divisor
}
}

return ds.ToArray();
}
}
}

0 comments on commit 8dfbda3

Please # to comment.