标签:
1 /* 2 题目:完全数 3 author taoliu——alex 2016.10 4 5 */ 6 7 8 #include <stdio.h> 9 10 11 void perfectnum(int n) 12 { 13 14 int perfect[100]={0}; 15 int sum=0; 16 for (int i = 1; i < n; i++) 17 { 18 if (n%i==0) 19 { 20 perfect[i]=i; 21 sum=sum+i; 22 } 23 } 24 if (sum==n) 25 { 26 printf("the number %d is perfect number!\n",n); 27 printf("the number %d is made up as follow!\n",n); 28 for (int i = 0; i < 100; i++) 29 { 30 if (perfect[i]!=0) 31 { 32 printf("%d ", perfect[i]); 33 } 34 } 35 36 } 37 //else 38 // printf("%d is not perfect number!\n",n ); 39 40 41 } 42 43 int main() 44 { 45 46 47 //可以输入你想要判断的数字 48 /* 49 int n; 50 printf("please input the number you want to judge! \n"); 51 scanf("%d",&n); 52 perfectnum(n); 53 */ 54 //也可以输出在某一范围内的所有完全数 55 printf("please input the scope you want to find! \n"); 56 int scope; 57 scanf("%d",&scope); 58 59 for (int i = 1; i < scope; ++i) 60 { 61 perfectnum(i); 62 } 63 return 0; 64 65 }
标签:
原文地址:http://www.cnblogs.com/tao-alex/p/5933474.html