一个数恰好等于它的因子之和,这个数就称作完数。例如:6=1+2+3;编程序找出1000之内的完数。
include<stdio.h>
void Factor(int num);
int main(void){
for(int i=1;i<=1000;i++){
Factor(i);
}
}
void Factor(int num){
int count=0;
int sum=0;
for(int i=1;i<=num/2;i++){
if(num%i==0){
sum+=i;
count++;
}
}
//output factor
if(sumnum){
printf("%d its factors are ",num);
int i;
for(i=1;i<=num/2&&count>1;i++){
if(num%i0){
printf("%d,",i);
count--;
}
}
//output the last factor.
while(i<=num/2){
if(num%i==0)
printf("%d\n",i);
i++;
}
}
}
标签:count,int,void,num,完数,Factor From: https://www.cnblogs.com/zhongta/p/18153312