C语言判断完数:算法实现与代码示例
#include <stdio.h>
int wanshu(int n) { int x = 0, i;
for (i = 1; i <= n / 2; i++)
{
if (n % i == 0)
{
x = x + i;
}
}
if (x == n)
{
return 1;
}
else
{
return 0;
}
}
int main() { int n, i;
for (n = 1; n <= 1000; n++)
{
if (wanshu(n))
{
printf('%d
', n); } } return 0; }
原文地址: https://www.cveoy.top/t/topic/n4ou 著作权归作者所有。请勿转载和采集!