#include <iostream> #include <iomanip> #include <list> using namespace std; int sqrts(int test); void compare(int val, int com); int main() { int input; int result; list<int> l; cin>>input; while(input != 0) { l.push_back(input); cin>>input; } cout<<"PERFECTION OUTPUT"<<endl; list<int>::iterator iter = l.begin(); while( iter != l.end() ) { result = sqrts(*iter); compare(*iter, result); ++iter; } cout<<"END OF OUTPUT"<<endl; return 0; } int sqrts(int test) { int temp = 0; for(int i = 1 ; i < test ; i++) { if(test%i == 0) { temp = temp + i; } } return temp; } void compare(int val, int sum) { if(val > sum) cout<<setw(5)<<val<<" DEFICIENT"<<endl; else if(val == sum) cout<<setw(5)<<val<<" PERFECT"<<endl; else cout<<setw(5)<<val<<" ABUNDANT"<<endl; }
Sunday, November 7, 2010
ACM-382 Perfection with C++
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment