计算完数的代码
(2010-10-26 19:41:01)
标签:
娱乐 |
-------------------------------------------------------------------------------------------------
#include <stdio.h>#include <stdlib.h>bool perfect(int x){int step=1;int a=0;while (x>step){ if(x%step==0) { a=a+step; } step=step+1; } if(x!=a){ return 0; } else{ return 1; } }int main(){int top=1;int step=1;int bottom=999999;int a;int n;int sum=0;for(n=top;n<=bottom;n=n+step){a=perfect(n); if(a==1) { printf("%d是完数\n",n); sum=sum+1; } }printf("运算完毕\n");printf("sum=%d",sum);system ("pause");return 0;}
前一篇:《古·玩》歌词小赏

加载中…