c++程序—水仙花数

#include<iostream>
using namespace std;
#include<string>
#include<ctime>

int main()
{
    //找出100~999中的水仙花数
    int num = 100;

    do 
    {
        int a = 0;
        int    b = 0;
        int c = 0;
        a = num % 10;
        b = num/10 % 10;
        c = num / 100;
        if (a*a*a+ b*b*b + c*c*c == num) 
        {
            cout << num << endl;
        }
        num++;
    } while (num < 1000);
    
    system("pause");
    return 0;

}

 

posted @ 2020-02-29 13:14  Jackie_Wang  阅读(3131)  评论(0编辑  收藏  举报