为啥我写的程序和答案对不上 检查不出自己的错误
题目是一个数如果所有因子之和为其本身则称为完数 要求输出1000以内的完数例如6=1+2+3;则6是完数输出格式 6 its factor are 1,2,3
#include<stdio.h>
int main()
{
int a=0,b,c[1000],i,j,k=0,m;
for(i=2;i<=1000;i++)
{
for(j=1;j<i;j++)
{
if(i%j==0)
{
c[k]=j;
a=a+c[k];
k++;
}
}
if(a==i)
{ printf("%d its factors are ",i);
for(m=0;m<k;m++)
printf(",%d",c[m]);
printf("\n");
}
a=0;
}
return 0;
}
6 its factors are ,1,1,1,2,1,1,2,3
28 its factors are ,1,1,1,2,1,1,2,3,1,1,2,4,1,3,1,2,5,1,1,2,3,4,6,1,1,2,7,1,3,5,
1,2,4,8,1,1,2,3,6,9,1,1,2,4,5,10,1,3,7,1,2,11,1,1,2,3,4,6,8,12,1,5,1,2,13,1,3,9,
1,2,4,7,14
Press any key to continue
这是我的结果;
答案是
6 its factor are 1,2,3
28 its factor are 1,2,4,7,14
496 its factor are 1,2,4,8,16,31,62,124,248