主题:完数怎么求
// 求1000内的所有完数
// 06-4-26
#include <iostream>
using namespace std;
int main()
{
int num, n, m, yinzi, sum = 1, j, x, i = 0, a[1000];
for(num = 1;num <= 1000;num++)
{
n = m = num;
for(yinzi = 1;;yinzi++)
{
if(sum == n)
{
cout << "its factors are ";
for(x = 0;x <= i;x++)
cout << a[x] << " ";
cout <<endl;
i = 0;
break;
}
}
}
return 0;
}
这是我做的,但是不对,请大虾指教!
// 06-4-26
#include <iostream>
using namespace std;
int main()
{
int num, n, m, yinzi, sum = 1, j, x, i = 0, a[1000];
for(num = 1;num <= 1000;num++)
{
n = m = num;
for(yinzi = 1;;yinzi++)
{
if(sum == n)
{
cout << "its factors are ";
for(x = 0;x <= i;x++)
cout << a[x] << " ";
cout <<endl;
i = 0;
break;
}
}
}
return 0;
}
这是我做的,但是不对,请大虾指教!