Home > php教程 > php手册 > PHP求小于1000的所有水仙花数的代码

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

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-06-13 12:03:21
Original
904 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";
  }
  }
  ?>

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
Latest Issues
php data acquisition?
From 1970-01-01 08:00:00
0
0
0
PHP extension intl
From 1970-01-01 08:00:00
0
0
0
How to learn php well
From 1970-01-01 08:00:00
0
0
0
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template