
header("Content-type:text/htmlcharset=utf-8")
$count = 0//该变量用来统计素数个数,并初始化为0
echo "素数:"
for($i=2$i<34$i++)
{
for($j=2$j<=intval(sqrt($i))$j++)
{
if($i%$j==0)
{
$isPrime=false
break
}
$isPrime=true
}
if($isPrime)
{
$count = $count + 1//是素数,所以统计变量加1
echo $i ." "
}
}
echo "素数的个数为:".$count
?>
create proc dbo.Usp_IsSuShu(@No int)as
begin
if @No <=1
return 0
declare @maxV int, @Index int
set @maxV = @No -1
set @Index = 2
while @Index < @maxV
begin
declare @maxV2 int,@Index2 int
set @maxV2 = @maxV
set @Index2 = @Index
while @Index2 < @maxV2
begin
if @Index2 * @Index = @No
select 0
set @Index2 = @Index2 + 1
end
set @Index = @Index + 1
end
select 1
end
dbo.ChkIntIsSuShu(13) -- 返回值1,表示素数,0表示非素数。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)