#include "stdio.h"
#include "conio.h"
main()
{
int k[10];
int i,j,n,s;
for(j=2;j<1000;j++)
{
n=-1;
s=j;
for(i=1;i
if((j%i)==0)
{
n++;
s=s-i;
k[n]=i;
}
}
if(s==0)
{
printf("%d its facter are ",j);
for(i=0;i
printf("%d\n",k[n]);
}
}
}
你好 ,这是我编的求完全数的程序,我运行了一下,没问题的,希望对你有帮助!
#include
#define SCOPE 1000
#define TRUE 1
#define FALSE 0
int Factors[N];
int isFactor(int num,int vector)
{
int result = FALSE;
if( num % vector == 0)
{
result =TRUE;
}
return result;
}
main()
{
int sum,target;
int result,i,count;
for(target = 2;target<=SCOPE;target++)
{
sum = 0;
count=0;
for(i=1;i<=target/2;i++)
{
if(isFactor(target,i))
{
sum += i;
Factors[count++] = i;
}
}
if(sum == target)
{
printf("%d\t",target);
printf("its factors are:");
for(i=0;i
printf("%d,",Factors[i]);
}
printf("\n");
}
}
}