php 求质素(素数) 的实现代码_PHP教程

WBOY
Lepaskan: 2016-07-21 15:30:53
asal
839 orang telah melayarinya

复制代码 代码如下:

class timer
{
var $time_start;
var $time_end;

function __construct()
{
$this->time_start = 0;
$this->time_end = 0;
}

function timer()
{
$this->__construct();
}

function start()
{
list($usec,$sec) = explode(" ",microtime());
$this->time_start = (float)$usec + (float)$sec;
}

function stop()
{
list($usec,$sec) = explode(" ",microtime());
$this->time_end = (float)$usec + (float)$sec;
}

function show($output = false)
{
$total = $this->time_end - $this->time_start;
if ($output) {
echo $total," sec";
return true;
}
return $total." sec";
}

}
?>
echo 'check prime
';
function IsPrime($i)
{
if($i{
return false;
}
//var $iterator;
for($iterator = 2 ; $iterator {
if($i % $iterator==0)
{
return false;
}
}
return true;
}

$sw=new timer();
$sw->start();
for($j=1;$j{
if(IsPrime($j))
{
echo 'true
';
}
else
{
echo 'false
';
}
}
$sw->stop();
$sw->show(true);

?>

www.bkjia.comtruehttp://www.bkjia.com/PHPjc/323176.htmlTechArticle复制代码 代码如下: ?php class timer { var $time_start; var $time_end; function __construct() { $this-time_start = 0; $this-time_end = 0; } function timer() { $this-__constr...
sumber:php.cn
Kenyataan Laman Web ini
Kandungan artikel ini disumbangkan secara sukarela oleh netizen, dan hak cipta adalah milik pengarang asal. Laman web ini tidak memikul tanggungjawab undang-undang yang sepadan. Jika anda menemui sebarang kandungan yang disyaki plagiarisme atau pelanggaran, sila hubungi admin@php.cn
Tutorial Popular
Lagi>
Muat turun terkini
Lagi>
kesan web
Kod sumber laman web
Bahan laman web
Templat hujung hadapan
Tentang kita Penafian Sitemap
Laman web PHP Cina:Latihan PHP dalam talian kebajikan awam,Bantu pelajar PHP berkembang dengan cepat!