C++ Program to check whether a number is an Abundant Number or not

Program to check whether a number is an Abundant number or not

Here we will discuss how to check whether a number is an Abundant number or not using C++ Programming language.

Abundant number is an number in which the sum of the proper divisors of the number is greater than the number itself.

To check for Abundant number, find and add the proper divisors of the number , compare the sum with the number if the sum is greater than the number than the number is an Abundant number else not an Abundant number. 

Program to check whether a number is an abundant number or not

Algorithm:-

  1. Take input from the user
  2. Input is stored in an int type variable say num.
  3. A loop is started
    1. Proper divisors of the number is found.
    2. Divisors are added to another variable ,sum(initial value 0).
    3. The loops works until all the divisors are not added.
  4. sum is compared with num
    1. if sum is greater than num then num is an Abundant number
    2. otherwise num is not an Abundant number.

C++ Code:-

    
    //C++ Program
    //Abundant Number or not
    #include<iostream>
    using namespace std;
    //main Program
    int main ()
    {  
        int  divnumsum=0;
        cout << “Enter the number to check : “;
        //user input
        cin >> num;
        //loop to find the sum of divisors
        for (int i=1i < numi++)
        {
        div = num % i;
            if (div == 0)
            sum += i;
        }
        //checking for Abundant number
        if (sum > num)
            cout<< num <<” is an Abundant number.”;
        else
            cout<< num <<” is not an Abundant number.”;
        return 0;
    }

    Output

    Enter the number to check : 24
    24 is an Abundant number.