WAP to divisors of a given number also check whether the given number is defined perfect or abundant in c++ programming
#include <iostream>
using namespace std;
int main() {
int num, sum = 0;
cout << "Enter a positive integer: ";
cin >> num;
if (num <= 0) {
cout << "Please enter a positive integer." << endl;
} else {
// Find the divisors and calculate their sum
for (int i = 1; i < num; ++i) {
if (num % i == 0) {
sum += i;
}
}
// Check the number is perfect, abundant, or deficient using the if condition
if (sum < n) {
cout << n<< " is a deficient number." << endl;
} else if (sum == n) {
cout << n << " is a perfect number." << endl;
} else {
cout << n << " is an abundant number." << endl;
}
}
return 0;
}
Output :-
Enter a positive integer: 1
1 is a deficient number.