check number is perfect number or not using c#

By j Miracle

here i show you to check the given number is perfect number or not.

here  we can check the number is perfect number or not using the following code.

public bool IsPerfectNumber(int no)
{
            int i, j;
            int sum = 0;

             for (i = 1; i <= no; i++)
             {

                 if (no % i == 0)
                {
                    j = no / i;

                      if (j != no)
                         sum = sum + j;

                  }
             }
             if (sum == no)

                 return true;

             else
          

     return false;

}

check number is perfect number or not using c#  (2331 Views)