Exemplo n.º 1
0
        public PerfectChecker(int number)
        {
            FactorFinder myFinder = new FactorFinder(number);

            _myNumber    = myFinder.GetMyNumber();
            FactorsFound = myFinder.Factors;
            int count = 0;

            for (int i = 1; i <= _myNumber; i++)
            {
                if (_myNumber % i == 0)
                {
                    count++;
                }
            }

            FactorsFound = new int[count];
            count        = 0;
            for (int i = 1; i <= _myNumber; i++)
            {
                if (_myNumber % i == 0)
                {
                    FactorsFound[count] = i;
                    count++;
                }
            }

            int sum = 0;

            for (int i = 0; i < FactorsFound.Length - 1; i++)
            {
                sum += FactorsFound[i];
            }
            if (sum == _myNumber)
            {
                IsPerfect = true;
            }
            else
            {
                IsPerfect = false;
            }
        }
Exemplo n.º 2
0
        public PrimeChecker(int number)
        {
            FactorFinder myFinder = new FactorFinder(number);

            myNumber     = myFinder.GetMyNumber();
            FactorsFound = myFinder.Factors;

            int count = 0;

            for (int i = 1; i <= myNumber; i++)
            {
                if (myNumber % i == 0)
                {
                    count++;
                }
            }

            FactorsFound = new int[count];
            count        = 0;
            for (int i = 1; i <= myNumber; i++)
            {
                if (myNumber % i == 0)
                {
                    FactorsFound[count] = i;
                    count++;
                }
            }

            if (FactorsFound.Length == 2)
            {
                IsPrime = true;
            }
            else
            {
                IsPrime = false;
            }
        }