方法一:#include<stdio.h>
int select(int b[],int x,int y);
int main()
{
int m,n,N,i,q,a[1000];
scanf("%d",&N);
for(i=1;i<=N;i++)
{
q=-1;
for(m=1;m<i;m++)
{
if(i%m==0)
{
q++;
a[q]=m;
}
}if(select(a,q,i))
{
printf("%d its factors are ",i);
for(n=0;n<=q;n++)
printf("%d ",a[n]);
printf("\n");
}
}
}
int select(int b[],int x, int y)
{
int p,q=0;
for(p=0;p<=x;p++)
{
q+=b[p];
}if(q==y)
return 1;
return 0;
}
方法二:#include<stdio.h>
int main()
{
int N,i,m,n,q,a[500],sum;
scanf("%d",&N);
for(i=1;i<=N;i++)
{
q=-1;sum=0;
for(m=1;m<i;m++)
{
if(i%m==0)
{
q++;
a[q]=m;
sum+=m;
}
}
if(sum==i)
{
printf("%d its factors are ",i);
for(n=0;n<=q;n++)
{
printf("%d ",a[n]);
}
}printf("\n");
}
}