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);
    }
    
}

发布了3 篇原创文章 · 获赞 1 · 访问量 34

猜你喜欢

转载自blog.csdn.net/qq_42052733/article/details/104504678