先建立个判断函数,然后执行该族孙祥函数,具凯配体如下:
create function ChkIntIsSuShu(@No int)
returns tinyint
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
return 0
set @Index2 = @Index2 + 1
end
set @Index = @Index + 1
end
return 1
end
select dbo.ChkIntIsSuShu(13) -- 返回值1,表示素兆搏数,0表示非素数。
Hi我,我来回答吧:先建立闭态个判断函数,然后执行该函数,具体如下:
create function ChkIntIsSuShu(@No int)
returns tinyint
as
begin
if @No <=1
return 0
declare @maxV int, @Index int
set @maxV = @No -1
set @Index = 2
declare @maxV2 int,@Index2 int
set @maxV2 = @maxV
set @Index2 = @Index
while @Index <@maxV
begin
while @Index2 <@maxV2
begin
if @Index2 * @Index = @No
return 0
set @Index2 = @Index2 + 1
end
set @Index = @Index + 1
end
return 1
end
select dbo.ChkIntIsSuShu(13) -- 返信银回值1,表示素数,0表示非素数。滑态宴
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)