编写程序,求所有水仙花数的问题

来源:百度知道 编辑:UC知道 时间:2024/06/24 17:01:18
4.编写程序输出所有水仙花数(153=13+53+33)

#include <iostream>
using namespace std;
int main ()
{int i,j,k,n;
cout<<"narcissus numbers are:"<<endl;
for (n=100;n<1000;n++)
{i=n/100;
j=n/10-i*10;
k=n%10;
if (n == i*i*i + j*j*j + k*k*k)
cout<<n<<" ";
}
cout<<endl;
return 0;
}