Initial commit

This commit is contained in:
Mark J Price 2022-02-19 19:56:52 +00:00
parent e523533d17
commit 10cceacca6
50 changed files with 1280 additions and 0 deletions

View file

@ -0,0 +1,9 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
</Project>

View file

@ -0,0 +1,39 @@
namespace Ch04Ex02PrimeFactorsLib
{
public class Primes
{
public static int[] PrimeNumbers = new[]
{
97, 89, 83, 79, 73, 71, 67, 61, 59, 53,
47, 43, 41, 37, 31, 29, 23, 19, 17, 13,
11, 7, 5, 3, 2
};
public static string PrimeFactors(int number)
{
string factors = string.Empty;
foreach (int divisor in PrimeNumbers)
{
int remainder;
do
{
remainder = number % divisor;
if (remainder == 0)
{
number = number / divisor;
if (number == 1)
{
factors += $"{divisor}";
}
else
{
factors += $"{divisor} x ";
}
}
} while (remainder == 0);
}
return $"{factors}";
}
}
}