A perfect number is a positive integer that is equal to the sum of its proper positive divisors, that is,
the sum of its positive divisors excluding the number itself (其正因數的總和,但不包含自己本身)
Ex: is 6 a perfect number?
since 1,2,3 are proper positive divisors of 6 , and the sum of them = 1+2+3 = 6
Thus , 6 is a perfect number
The question is :
Given a integer number N, print out all the perfect number <= N
In this problem, you only need to implement a function called isPerfect(int n).
It returns 1 if the number is perfect number , otherwise returns 0.
Main program is below. It calls the function you implement and print out the results.
---------------------------------------------------------------------------------------------------------
#include <stdio.h>
//-------------------------------------------
// Implement the function here
//-------------------------------------------
int main(){
int N, i;
scanf("%d",&N);
for(i=1; i<=N; i++){
if(1==isPerfect(i)) printf("%d\n",i);
}
}
----------------------------------------------------------------------------------------------------------
There is only a integer N. (N<=10000)
All perfect numbers that are smaller or equal to N