习题2-2,水仙花数

来源:互联网 发布:淘宝卖家账号 编辑:程序博客网 时间:2024/05/29 13:49

输出100~999中的所有水仙花数。若3位数ABC满足ABC=A^3+B^3+C^3,则称其为水仙花数。

#include <iostream>using namespace std;int main(){    int i,a,b,c;    for( i = 100 ; i <= 999 ; ++i )    {         a=i%10;         b=(i/10)%10;         c=i/100;         if( a*a*a+b*b*b+c*c*c==i )         cout<<i<<endl;    }    system("pause");    return 0;}
原创粉丝点击