美文网首页
C语言 找出四叶玫瑰数

C语言 找出四叶玫瑰数

作者: 863cda997e42 | 来源:发表于2018-02-08 15:35 被阅读1169次
#include <stdio.h>
 
bool isRoseNumber(int num);

int main()
{
    for(int i = 1000; i < 10000; i++)
    {
        if(isRoseNumber(i)){
            printf("%d is rose number.\n", i);
        }
    }
    return 0;
}

bool isRoseNumber(int num)
{
    int a, b, c, d;
    a = num / 1000;
    b = (num / 100) % 10;
    c = (num / 10) % 10;
    d = num % 10;
    return ((a * a * a * a + b * b * b * b + c * c * c * c + d * d * d * d) == num);
}

结果如下:

1634 is rose number.
8208 is rose number.
9474 is rose number.
Press any key to continue

相关文章

网友评论

      本文标题:C语言 找出四叶玫瑰数

      本文链接:https://www.haomeiwen.com/subject/lbuttftx.html