用C程序编写一个数如果恰好等于他的因子之和,这个数就称为完数,找出1000之内所有的完数,

来源:百度知道 编辑:UC知道 时间:2024/05/13 14:05:15
并按下面格式输出其因子;6 its factors are 1,2,3
这个没有按照因子输出啊~

main(){
int i,j,s;
for (i=1;i<=1000;i++){
s=0;
for (j=1;j<i;j++) if (i%j==0) s+=j;
if (i==s) {
printf("%d its factors are ",i);
for (j=1;j<i;j++) if (i%j==0) printf("%d ",j);
printf("\n");
}
}
}

程序运行结果如下:
6 its factors are 1 2 3
28 its factors are 1 2 4 7 14
496 its factors are 1 2 4 8 16 31 62 124 248