Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

A number is said to be deficient, perfect, or abundant if the sum of its proper

ID: 3650023 • Letter: A

Question

A number is said to be deficient, perfect, or abundant if the sum of its proper divisors ( its factors including 1 but not the number itself) is less than, equal to, or greater than the number respectively. For example, 10 is deficient since 1 + 2 + 5 < 10; 6 is perfect since 1 + 2 + 3 = 6; 20 is abundant since 1 + 2 + 4 + 5 + 10> 20. Write a program that prompts the user for a positive integer and tells the user whether the number is deficient, perfect, or abundant. Your program should continue until the user enters -1.

Explanation / Answer

Please rate...

Program:

=====================================================

#include<iostream>
using namespace std;
int main()
{
    int a=1;
    cout<<" Enter a positive number: ";
    cin>>a;
    while(a!=-1)
    {
        int i,s=0;
        for(i=1;i<=a-1;i++)
        {
            if(a%i==0)
            {
                s=s+i;
                cout<<i<<" + ";
            }
        }
        cout<<"";
        cout<<" ";
        if(s<a)
        {
            cout<<"< "<<a;
            cout<<" The number is deficient";
        }
        if(s>a)
        {
            cout<<"> "<<a;
            cout<<" The number is abundant";
        }
        if(s==a)
        {
            cout<<"= "<<a;
            cout<<" The number is perfect";
        }

        cout<<" Enter a positive number: ";
        cin>>a;


    }
}

=============================================================

Sample output:

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote