C++找出100-999以内的水仙花数

IDE:codeblocks

日期:2019/11/30

功能:找出100-999以内的水仙花数

所谓水仙花数是指3位正整数的各位的数字的立方和等于该数本身。例如:153就是水仙花数

#include <iostream>
using namespace std;

int isflower(int n)
{
    int a,b,c;
    a=n/100;
    b=n%100/10;
    c=n%100%10;
    if(n==a*a*a+b*b*b+c*c*c)
        return 1;
    else
        return 0;
}

int main()
{
    int i,a,b,c;
    for(i=100;i<1000;i++)
    {
        if(isflower(i))
        {
            cout<<i<<"是水仙花数"<<endl;
        }
    }
    return 0;
}



发布了57 篇原创文章 · 获赞 2 · 访问量 1875

猜你喜欢

转载自blog.csdn.net/weixin_43476969/article/details/103328904