write a program to check whether to accept a number and check whether the number is excessive or deficient or perfect number
Answers
Answer:
STEP 1: START.
STEP 2: SET sum= 0.
STEP 3: REPEAT STEP 4 UNTIL i<=? n.
STEP 4: if (n% i==0) then. if(n/i==i) sum=sum+i. else. sum=sum+i. sum=sum+ (n/i)
STEP 5: RETURN sum.
STEP 6: END.
Explanation:
PLEASE MARK AS BRAINLIST
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;
}
Explanation:
Check this maybe this could help!