Answers for "c++ check if the number is equal to the sum of its divisors excluding itself"

0

c++ check if the number is equal to the sum of its divisors excluding itself

// not my code but I found it very useful so I just pasted it
// in order to help others

int i, num, div, sum=0;
    cout << "Enter the number to be checked : ";
    cin >> num;
    for (i=1; i < num; i++)
    {
        div = num % i;
        if (div == 0)
            sum = sum + i;
    }
    if (sum == num)
        cout << "\n" << num <<" is a perfect number.";
    else
        cout << "\n" << num <<" is not a perfect number.";
Posted by: Guest on December-30-2020

Code answers related to "c++ check if the number is equal to the sum of its divisors excluding itself"

Code answers related to "TypeScript"

Browse Popular Code Answers by Language