问答详情
源自:4-9 循环结构之for循环(二)

为什么这样不行?


#include <stdio.h>

int main()

{

    //定义三位数num,个位数sd,十位数td,百位数hd

    int num, sd, td, hd;

    //循环所有三位数

    for(num = 100    ; num<1000    ;  num++    )

    {

        //获取三位数字num百位上的数字

        hd = num/100                ;

        //获取三位数字num十位上的数字

        td = num%100/10                ;

        //获取三位数字num个位上的数字

        sd = num%10                ;

        //水仙花数的条件是什么?

        if(hd^3+td^3+sd^3==num) 

        {

            printf("水仙花数字:%d\n", num);    

        }

    }

    return 0;    

}

   

输出把100——999的数字都输出出来了

提问者:郭思杰 2019-02-24 16:08

个回答

  • qq_宝慕林1262008
    2019-02-24 19:47:31
    已采纳

    C语言里^在这个符号不能用吧


  • qq_宝慕林1262008
    2019-02-24 19:49:14

    把你的if语句判定条件改成这个if(hd*hd*hd+td*td*td+sd*sd*sd==num)