详解在代码中已标示,数据范围可更改

                       //自己摸索的水仙花数(φ(◎ロ◎;)φ)

#include<tgmath.h>

#include<math.h>

int main()

{

int sum = 0;

int i = 0;

//floor为向下取整符号,对数函数算出的指数即位数减一  头文件#include<tgmath.h>

for (i = 1;i <= 1000;i++)

{

 int sum = 0;

 int j = floor(log10(i) + 1);

 int a = floor(log10(i) + 1);

 int b = i;

 //double pow(x,y)表示x的y次方 #include<math.h>(int)为强制取整

 while(j > 0)

 {

  int k = b / pow(10,j-1);

  sum += pow(k, a);

  b = b % (int)pow(10, j - 1);

  j--;

 }

 if (i == sum)

 {

  printf("%d ", i);

 }

}

return 0;

}

水仙花数的打印(仅个人探索)_取整

阿里云国内75折 回扣 微信号:monov8
阿里云国际,腾讯云国际,低至75折。AWS 93折 免费开户实名账号 代冲值 优惠多多 微信号:monov8 飞机:@monov6