编程序找出1000之内的所有完数,并按下面格式输出其因子;6 its facter are 1,2,3

C语言 编程题
2024-12-12 19:24:00
推荐回答(2个)
回答1:

#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,",k[i]);
printf("%d\n",k[n]);
}
}

}

你好 ,这是我编的求完全数的程序,我运行了一下,没问题的,希望对你有帮助!

回答2:

#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");
}
}
}