- #include<stdio.h>
- #include<math.h>
- //获取一个整数是不是完数
- bool isPerfect(int num)
- {
- int sum = 1, factor = 2;
- for (factor; factor < num; ++factor)
- {
- if (num % factor == 0)
- sum += factor;
- }
- if (sum == num)
- return true;
- else
- return false;
-
- }
- int main()
- {
- int num = 6, count = 0;
- //找出0-10000之间的所有的完数
- for (num; num < 10000; ++num)
- {
- if (isPerfect(num))
- {
- printf("%d is a perfect number.\n", num);
- }
- }
- return 0;
- }
复制代码 |