private static void PrintResults(FactorResult result) { Console.WriteLine("The number you selected was {0}", result.Number); Console.WriteLine("The factors are: {0}", string.Join(",", result.Factors)); Console.WriteLine("Perfect? {0}", result.IsPerfect); Console.WriteLine("Prime? {0}", result.IsPrime); }
private bool CheckPerfect(FactorResult result) { int sum = 0; for (int i = 0; i < result.Factors.Count; i++) { sum += result.Factors[i]; } return sum == result.Number; }
public FactorResult CheckFactors(int number) { FactorResult result = new FactorResult(); result.Number = number; result.Factors = GetFactors(number); result.IsPerfect = CheckPerfect(result); result.IsPrime = CheckPrime(result); return result; }
private bool CheckPrime(FactorResult result) { return result.Factors.Count == 1; }