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;

}

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM