您的位置:首页 > 其它

360在线笔试题:水仙花数

2015-08-10 18:40 211 查看
[code]#include<iostream>
#include <math.h>
using namespace std;

int main()
{
    int m = 0, n = 0;
    int index = 0;
    int bai= 0, shi = 0,ge = 0;
    int count = 0;

    while((cin >> m >> n) )
    {
        count = 0;
        for(index = m; index <= n; index++)
        {
            bai = index/100;
            shi = index%100/10;
            ge = index%10;
            if(index == (pow(bai,3)+pow(shi,3)+pow(ge,3)))
            {
                count++;
                if(count == 1)
                {
                    cout << index;
                }
                else
                {
                    cout << " " << index;
                }
            }

        }
        if(count == 0)
        {
            cout << "no";
        }
        cout << endl;
    }

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: