#include <iostream> using namespace std; int main(){ int n,j,sum; while (cin >> n){ sum=0; j= 1; while(j<n) { if ((n%j) == 0) { sum=sum+ j ; } j++ ; } if ( sum>n ){ cout << "盈數" << endl; } else if ( sum<n ) { cout << "虧數" << endl; } else { cout << "完全數" << endl; } } }
#include <iostream> using namespace std; int main(){ int n,j,sum; while (cin>>n){ sum=0; j=1 ; for(j=1;j<n;j++){ if ((n%j) == 0) { sum= sum+ j ; } ; } if ( sum>n ){ cout << "盈數" << endl; } else if ( sum<n ) { cout << "虧數" << endl; } else { cout << "完全數" << endl; } } } Close
CPP
EZ
|