Example 1:
Copy CodeThe code is as follows:
for ($q =1; $q <=9; $q + +) {
for ($w =0; $w <=9; $w + +) {
for ($e =0; $e <=9; $e + +) {
if ($q * $q * $q + $w * $w * $w + $e * $e * $e = =
100* $q + 10* $w + $e) {
echo "$q $w $e".
";
}
}
}
}
?>
Example 2:
copy code code is as follows:
!--? PHP function cube ($n)
{
Return $n * $n * $n;
}
Function is_narcissistic ($n)
{
$hundreds = floor ($n/100);//Break out hundred
$tens = Floor ($n/10)% 10; Decompose the 10-bit
$ones = floor ($n% 10);//Break Out bits
Return (BOOL) (Cube ($hundreds) +cube ($tens) +cube ($ones) = = $n);
}
for ($i =, $i <, + + $i)
{
if (is_narcissistic ($i))
Echo $i. " \ n ";
}
?
Example 3:
Copy the Code code as follows:
Armstrong number: A K-digit, and the sum of the number of its digits on each bit is equal to its own. (Example: 1^3 + 5^3 + 3^3 = 153)
Class Armstrong {
static function index () {
for ($i = n, $i < 100000; $i + +) {
echo Self::is_armstrong ($i)? $i. '
' : '';
}
}
static function Is_armstrong ($num) {
$s = 0;
$k = strlen ($num);
$d = Str_split ($num);
foreach ($d as $r) {
$s + = Bcpow ($r, $k);
}
return $num = = $s;
}
}
Armstrong::index ();
Example 4:
Copy the Code code as follows:
function Winter ($num)
{
if ($num <1000) {
Define Bits
$ge = $num% 10;
Define 10-bit
$ten = (($num%100)-$ge)/10;
Define the Hundred
/*floor rounding, ignoring all numbers after the decimal point */
$hundred =floor ($num/100);
$sum 1= $ge * $ge * $ge + $ten * $ten * $ten + $hundred * $hundred * $hundred;
if ($sum 1== $num) {
return 1;
} else{
return 0;
}
} else{
return-1;
}
}
if (Winter (371) ==-1) {
echo "number greater than 1000";
}else{
if (Winter (371)) {
echo "Yes";
}
else{
echo "No";
}
}
?>
http://www.bkjia.com/PHPjc/750859.html www.bkjia.com true http://www.bkjia.com/PHPjc/750859.html techarticle Example 1: Copy code as follows: PHP for ($q =1; $q =9, $q + +) {for ($w =0, $w =9; $w + +) {for ($e =0; $e =9; $e + +) {if ($q * $q * $q + $w * $w * $w + $e * $e * $e = = 100* $q + 10* $w + $e) {echo "$q $w $e ...