第三章课后习题(2)
19、水仙花数(三位数,各位数字的立方和等于该数字本身)
#include<iostream>
using namespace std;
int main(){
int n,t;
int n1,n2,n3;
for(n=100;n<1000;n++){
t=n;
n1=t/100;
t=t%100;
n2=t/10;
t=t%10;
n3=t;
if(n1*n1*n1+n2*n2*n2+n3*n3*n3==n){
cout<<n<<" ";
}
}
cout<<endl;
return 0;
}
20、1000以内的完数(数等于因数和)
#include<iostream>
#include<cmath>
using namespace std;
int main(){
int i;
int s;
for(i=1;i<1000;i++){
s=1;
for(int j