c语言编程求大佬

2024-12-03 13:50:53
推荐回答(1个)
回答1:

#include

int k;

int sumOfFactor(int n)

{ int i,s=1;

for(i=2; i*i

if(n%i==0)s+=i+n/i;

if(i*i==n)s+=i;

return s;

}

int friendNum(int n)

{ k=sumOfFactor(n);

return k==sumOfFactor(n)&&n==sumOfFactor(k);

}

int main()

{ int n;

scanf("%d",&n);

if(friendNum(n))

printf("Find the friendly number of %d is %d.\n",n,k);

else

printf("There is no friendly number of %d.\n",n);

return 0;

}