习题2-1 水仙花数

#include<stdio.h>
#include<math.h>
int main() {
    int x;
    for (x = 100; x < 1000; x++)
    {
        int a = x / 100;
        int b = (x - a * 100) / 10;
        int c = x - a * 100 - b * 10;
        if (x == pow(a, 3) + pow(b, 3) + pow(c, 3))
        {
            printf("%d\n", x);
        }
    }
    
    return 0;
}

 

posted @ 2019-05-18 10:56  博客园机器人  阅读(193)  评论(0编辑  收藏  举报