예제 #1
0
 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);
 }
예제 #2
0
        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;
        }
예제 #3
0
        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;
        }
예제 #4
0
 private bool CheckPrime(FactorResult result)
 {
     return result.Factors.Count == 1;
 }