编辑程序找出1000以内的玩完数并按下面格式输出其因子: 6 its factors are 1,2,3

2024-12-21 12:04:06
推荐回答(1个)
回答1:

#include
#include
void main()
{
int i,n,a,Sn;
for(n=2;n<=1000;n++)
{
a=sqrt(n);
for(Sn=0,i=1;i {if(n%i==0)
Sn=Sn+i;
}
if(Sn==n)
printf("%d its factors are ",n);
else
continue;
Sn = 0;
for(i=1;i {
if(n%i==0){
Sn += i;
if(Sn == n){
printf("%d", i);
}else{
printf("%d,",i);
}
}
}
printf("\n");
}
}