I have the following program, the perfect numbers won't print, only output are the numbers 1 and 2, which are not perfect. What's wrong, is it a scope problem or is it the loops? Adding break statement after print statement causes output of all numbers 1 - 99.
int sum = 0;
for (int i = 1; i < 100; i++) {
for (int j = 1; j <= i; j++) {
if (i % j == 0){
sum += j;}
if (sum == i){
printf("%d\n", i);
}
}
}