We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
-----------------sql server---------------------
declare @x int;
declare @y int;
declare @z int;
declare @count int;
declare @output NVARCHAR(MAX) = '';
SET @z = 1000;
SET @x = 2;
SET @y = 2;
SET @count = 0;
while @x < 1000
begin
while @y <= floor(sqrt(@x))
begin
if @x % @y = 0
begin
SET @count = @count + 1;
break;
end;
SET @y = @y + 1;
end;
if @count = 0
begin
SET @output = CONCAT(@output, CAST(@x as varchar), '&');
end;
SET @y = 2;
SET @x = @x + 1 ;
SET @count = 0;
Print Prime Numbers
You are viewing a single comment's thread. Return to all comments →
-----------------sql server--------------------- declare @x int; declare @y int; declare @z int; declare @count int; declare @output NVARCHAR(MAX) = ''; SET @z = 1000; SET @x = 2; SET @y = 2; SET @count = 0;
while @x < 1000 begin while @y <= floor(sqrt(@x)) begin if @x % @y = 0 begin SET @count = @count + 1; break; end; SET @y = @y + 1; end; if @count = 0 begin SET @output = CONCAT(@output, CAST(@x as varchar), '&');
end;
SET @output = LEFT(@output, LEN(@output) - 1); print @output;