题目内容
完全数,又称完美数或完数(Perfect Number),它是指这样的一些特殊的自然数,它所有的真因子(即除了自身以外的约数)的和,恰好等于它本身。例如,6就是一个完全数,是因为6 = 1 + 2 + 3。请编写一个判断完全数的函数IsPerfect(),然后判断从键盘输入的整数是否是完全数。注意:1没有真因子,所以不是完全数。代码如下,按要求在空白处填写适当的表达式或语句,使程序完整并符合题目要求。#include #include int IsPerfect(int x); int main() { int m; printf("Input m:"); scanf("%d", &m); if (_________________) /* 完全数判定 */ 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 (__________________) { if (___________) total = total + i; } return total==x ? 1 : 0; }
查看答案
搜索结果不匹配?点我反馈
更多问题