题意为:输入一个数求它的因子和,并判断因子和与该数的大小关系
如果因子和大于该数输出DEFICIENT
如果因子和等于该数输出PERFECT
如果因子和小于该数输出ABUNDANT
需要注意的就是格式问题!!!
#include<stdio.h>
#include<math.h>
#include<string>
#include<string.h>
#include<cstring>
#include<string.h>
#include<algorithm>
#include<iomanip>
#include<iostream>
using namespace std;
int main() {
int n, sum;
char str1[8] = "PERFECT", st2[9] = "ABUNDANT", str3[10] = "DEFICIENT";
cout << "PERFECTION OUTPUT" << endl;
while(scanf("%d", &n) != EOF && n){
sum = 0;
for(int i=1; i<n; ++i){
if(sum > n){
cout << setw(5) << n << " "<< st2 << endl;
break;
}
if(n%i == 0)
sum += i;
}
if(sum == n)
cout << setw(5) << n << " " << str1 << endl;
else if(sum < n)
cout << setw(5) << n << " " << str3 << endl;
}
cout << "END OF OUTPUT" << endl;
return 0;
}