Q:

Write a program in C++ to check whether a given number is Deficient or not

0

Write a program in C++ to check whether a given number is Deficient or not

Sample Output:

Check whether a given number is an Deficient number:                  
 --------------------------------------------------------              
 Input an integer number: 25                                           
 The number is Deficient.

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

#include <bits/stdc++.h>
using namespace std;
int getSum(int n)
{
    int sum = 0;
    for (int i=1; i<=sqrt(n); i++)
    {
        if (n%i==0)
        {
            if (n/i == i)
                sum = sum + i;
            else 
            {
                sum = sum + i;
                sum = sum + (n / i);
            }
        }
    }
    sum = sum - n;
    return sum;
}
bool checkDeficient(int n)
{
    return (getSum(n) < n);
}
int main()
{
int n;
 cout << "\n\n Check whether a given number is an Deficient number:\n";
 cout << " --------------------------------------------------------\n";
cout << " Input an integer number: ";
cin >> n;
    checkDeficient(n)? cout << " The number is Deficient.\n" : cout << " The number is not Deficient.\n";
    return 0;
}

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now