int Perfectnumber (int rob) {
int result;
int sum = 0;
for (int i = 1; i < rob; i++) {
if (rob % i == 0) {
sum += i;
}
if (sum == rob) {
return true;
} else {
return false;
}
}
return true;
}
is wrong for a start
the if sum == rob statement should be outside of the for loop, otherwise your exiting after the first iteration, you need that loop to finish calculating sum before you do this if check.
for (int i = 1; i < lim; i++) {
rez=Perfectnumber(lim);
}
I don't understand why you need to check if n is a perfect number n amount of times. Perhaps you should look at your code and understand whats happening.