44 lines
849 B
C++

#include <iostream>
using namespace std;
int add(int number) {
int sum = 0;
while (number > 0) {
sum = sum + number % 10;
number = number / 10;
}
return sum;
}
void perfect_number(int number) {
int sum = 0;
for (int i = 1; i < number; i++) {
if (number % i == 0) {
sum = sum + i;
}
}
if (sum == number) {
cout << number << " is a perfect number";
} else {
cout << number << " is not a perfect number";
}
}
int main() {
int input_number;
for (;;) {
cout << "Input number: ";
cin >> input_number;
if (input_number > 0) break;
}
int sum = add(input_number);
cout << "Sum is " << sum << endl;
perfect_number(sum);
return 0;
}
// namesto while use for