0
I am trying to print all perfect number between a range but I am not getting desired output can someone can help me
2 Réponses
+ 1
void perfect(void){
int count = 0;
for ( int i = 1; i<=1000; i++ ){
for(int j =1; j<i; j++){
if(i%j==0){
count = count + j;
}
}
if(count == i){
cout<<i<<endl; // this if is outside, only check the sum of divisors after you find all the divisors
}
count = 0; // resets the sum of divisors back to 0, preparing for the next number
}
}
I changed a bit of your codes there. Please refer to the comments I wrote inside
0
Thanks bro now I get my desired result