C++ Exercises: Check whether a given number is Deficient or not
C++ Numbers: Exercise-6 with Solution
Write a program in C++ to check whether a given number is Deficient or not.
Pictorial Presentation:

Sample Solution:
C++ Code :
#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;
}
Sample Output:
Check whether a given number is an Deficient number: -------------------------------------------------------- Input an integer number: 25 The number is Deficient.
Flowchart:

C++ Code Editor:
Contribute your code and comments through Disqus.
Previous: Write a program in C++ to find Perfect numbers and number of Perfect numbers between 1 to 1000.
Next: Write a program in C++ to find the Deficient numbers (integers) between 1 to 100.
What is the difficulty level of this exercise?
- Weekly Trends
- Python Interview Questions and Answers: Comprehensive Guide
- Scala Exercises, Practice, Solution
- Kotlin Exercises practice with solution
- MongoDB Exercises, Practice, Solution
- SQL Exercises, Practice, Solution - JOINS
- Java Basic Programming Exercises
- SQL Subqueries
- Adventureworks Database Exercises
- C# Sharp Basic Exercises
- SQL COUNT() with distinct
- JavaScript String Exercises
- JavaScript HTML Form Validation
- Java Collection Exercises
- SQL COUNT() function
- SQL Inner Join