#include <math.h>
int IsPerfect(int x);
int main()
{
int m;
printf("Input m:");
scanf("%d", &m);
if (IsPerfect(m)) /* 完全數判定 */
printf("%d is a perfect number\n", m);
else
printf("%d is not a perfect number\n", m);
return 0;
}
/* 函數功能:判斷完全數,若函數返回0,則代表不是完全數,若返回1,則代表是完全數 */
int IsPerfect(int x)
{
int i;
int total = 0; /* 1沒有真因子,不是完全數 */
for (i=1;i<x;i++)
{
if (x%i == 0)
total = total + i;
}
return total==x ? 1 : 0;
}