因数求和与原数比较的问题,在cout中运用3目运算符较为方便
代码如下:
#include <iostream>
#include <iomanip>
using namespace std;
int main()
{
int a,b,i;
cout<<"PERFECTION OUTPUT"<<endl;
while(cin>>a&&a)
{
cout<<setw(5)<<a<<" ";
b=0;
for(i=1; i<=(int)(a/2); i++)
if(!(a%i))
b+=i;
cout<<(a<b?"ABUNDANT":(a>b?"DEFICIENT":"PERFECT"))<<endl;
}
cout<<"END OF OUTPUT"<<endl;
return 0;
}