Home >Backend Development >PHP Tutorial >Find the number of daffodils less than 1000 using PHP

Find the number of daffodils less than 1000 using PHP

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOriginal
2016-07-25 09:13:012122browse

In programming languages, the narcissus number is a number with n (>=3) digits, which is equal to the sum of each number raised to the nth power. For example, 153 is a daffodil number, 153=13+53+33. Write a program to solve all daffodil numbers less than 1000.

Example, PHP code to find the number of daffodils less than 1000.

  1. for($i=100;$i<1000;$i++){
  2.  $a=intval($i/100);
  3.  $b=intval($i/10) %10;
  4.  $c=$i%10;
  5.  if(pow($a,3)+pow($b,3)+pow($c,3)==$i){
  6.  echo $i." t";
  7.  }
  8.  }
  9. ?>
Copy code


Statement:
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