C语言实现输出所有的水仙花数

#include<stdio.h>
#include<math.h>
void main()
{
    int i;
    int x, y, z;
    for (i = 100; i < 1000; i++) 
    {
        x = i % 10;
        y = i % 100 / 10;
        z = i / 100;
        if (pow(x, 3) + pow(y, 3) + pow(z, 3) == i)
            printf("%d\n", i);
    }
    
}

运行结果:
运行结果

我的公众号!

在这里插入图片描述

posted @ 2021-06-02 19:55  国名老公阿航  阅读(2027)  评论(0编辑  收藏  举报