PHP求小于1000的所有水仙花数的代码_php技巧

WBOY
Release: 2016-05-17 09:13:34
Original
2320 people have browsed it

水仙花数是一个n(>=3)位数字的数, 它等于每个数字的n次幂之和. 例如, 153是一个水仙花数, 153=1³+5³+3³. 编写程序, 求解小于1000的所有水仙花数.

复制代码 代码如下:

    for($i=100;$i  $a=intval($i/100);
  $b=intval($i/10)%10;
  $c=$i%10;
  if(pow($a,3)+pow($b,3)+pow($c,3)==$i){
  echo $i."\t";
  }
  }
  ?>
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template