Home > php教程 > php手册 > 水仙花开

水仙花开

WBOY
Release: 2016-06-06 19:33:21
Original
1349 people have browsed it

算法,水仙花数 EQPHP ?phpclass a_test{private $static_class;static function index(){//for ( $i = 100; $i 1000000; $i++ ) { for ( $i = 100; $i 1000; ++$i ) {if (self::is_narcissus($i) )echo 'Narcissus: '.$i.'br';}}static function cube($num){

算法,水仙花数 EQPHP
<?php

class a_test{

private $static_class;

static function index(){
	//for ( $i = 100; $i < 1000000; $i++ ) {
        for ( $i = 100; $i < 1000; ++$i ) {

		if (self::is_narcissus($i) )
		echo 'Narcissus: '.$i.'<br>';
	}
}


static function cube($num){
	return $num * $num * $num;
}

static function is_narcissus($num){
	$hundreds = floor($num / 100);    //分解出百位
	$tens = floor($num / 10 ) % 10;    //分解出十位
	$ones = floor($num % 10 );    //分解出个位
	return (bool)(self::cube($hundreds)+self::cube($tens)+self::cube($ones) == $num);
}


}
Copy after login
Related labels:
source:php.cn
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
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template