正整数n的适当除数是除n本身以外的n个均匀除法的正整数。例如,16的适当除数是1、2、4和8。
富足数是大于0的整数,使得其适当的除数之和大于整数。例如,12非常丰富,因为1+2+3+4+6 = 16大于12。
亏数是大于0的整数,使得其适当的除数之和小于整数。例如,由于1+2+4 =7(小于8 ),因此8不足。
完美数是大于0的整数,使得其适当的除数之和等于整数。例如,6是完美的,因为1+2+3 =6。
#include <iostream>
#include <cctype>
#include <iomanip>
#include <cmath>
using namespace std;
int main()
{
int current;
int possible;
int sum=0;
int facts=0;
cin >> current;
目前为: 17 -5 246
while(cin){
cout << current;
for (possible=1; possible<= current; possible++)
{
if(current%possible==0)
{
sum= sum + possible;
facts++;
if(sum-current > current)
cout << "is abundant and has" << facts << "factors" << endl;
if(sum-current < current)
cout << "is deficient" << endl;
if(current < 2)
cout << "is not abundant, deficient or perfect" << endl;
if(current == sum-current)
cout << "is perfect" << endl;
}
}
}
return 0;
}
这就是我应该得到的: 17是不足-5不是丰富,不足或完美。246很丰富,有8个因素,而我却得到了一个无限循环。
发布于 2018-03-05 07:19:50
您可以使用int current3代替int current,并检查当前数组的接收端而不是while(cin)。
https://stackoverflow.com/questions/49105024
复制相似问题