Example 1:
Copy codeThe Code is as follows:
<? Php
For ($ q = 1; $ q <= 9; $ q ++ ){
For ($ w = 0; $ w <= 9; $ w ++ ){
For ($ e = 0; $ e <= 9; $ e ++ ){
If ($ q * $ q + $ w * $ w + $ e * $ e =
100 * $ q + 10 * $ w + $ e ){
Echo "$ q $ w $ e". "<p> ";
}
}
}
}
?>
Example 2:
Copy codeThe Code is as follows:
<? Php
Function cube ($ n)
{
Return $ n * $ n;
}
Function is_narcissistic ($ n)
{
$ Hundreds = floor ($ n/24/60); // hundreds of digits are decomposed.
$ Tens = floor ($ n/10) % 10; // break down ten
$ Ones = floor ($ n % 10); // Splits a single bit
Return (bool) (cube ($ hundreds) + cube ($ tens) + cube ($ ones) ==$ n );
}
For ($ I = 100; $ I <1000; ++ $ I)
{
If (is_narcissistic ($ I ))
Echo $ I. "\ n ";
}
?>
Example 3:
Copy codeThe Code is as follows:
<? Php
// Armstrong number: a k-digit number. The sum of the k-power of each digit is equal to itself. (For example, 1 ^ 3 + 5 ^ 3 + 3 ^ 3 = 153)
Class Armstrong {
Static function index (){
For ($ I = 100; $ I <100000; $ I ++ ){
Echo self: is_armstrong ($ I )? $ I. '<br> ':'';
}
}
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 codeThe Code is as follows:
<Html>
<Head>
<Title> </title>
</Head>
<Body>
<? Php
Function winter ($ num)
{
If ($ num <1000 ){
// Define a single bit
$ Ge = $ num % 10;
// Define ten
$ Ten = ($ num % 100)-$ ge)/10;
// Defines the hundred bits
/* Floor rounded up, ignoring all numbers after the decimal point */
$ Hundred = floor ($ num/100 );
$ Sum1 = $ ge * $ ge + $ ten * $ ten + $ hundred * $ hundred;
If ($ sum1 = $ 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 ";
}
}
?>
</Body>
</Html>