Php prints the daffodils function code
- Php daffodils function --bbs.it-home.org
- 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 ";
- }
- }
- ?>
Example 2: php implements daffodils
- For ($ I = 0; I I <1000; $ I ++)
- {
- $ A = floor ($ I/100); // obtain hundreds of digits
- $ B = floor ($ I/10) % 10; // Obtain ten digits
- $ C = $ I % 10; // Obtain the single digit
- // If ($ a * $ a + $ B * $ B + $ c * $ c = $ I)
- If (pow ($ a, 3) + pow ($ B, 3) + pow ($ c, 3) = $ I) // judge hundreds or ten digits
- Is the cube of a single digit equal to the number itself?
- {
- Echo $ I ."
";
- }
- }
- ?>
|