- # include <iostream.h>
- void main()
- {
- static int k[20];
- int i,j,n,s,m;
- cout<<"请输入要寻找完数的范围:";
- cin>>m;
- for (j=2;j<=m;j++)
- {
- n=0;
- s=j;
- for (i=1;i<j;i++)
- {
- if((j%i)==0)
- {
- n++;
- s=s-i;
- k[n]=i;
- }
- }
- if (s==0)
- {
- cout<<j<<"是一个完数,它的因子是:";
- for (i=1;i<=n;i++)
- cout<<k[i]<<" ";
- cout<<endl;
- }
- }
- }