You are viewing a single comment's thread. Return to all comments →
DECLARE @n INT = 1000; DECLARE @i INT = 2; DECLARE @j INT; DECLARE @isPrime BIT; DECLARE @result VARCHAR(8000) = '';
WHILE @i <= @n BEGIN SET @isPrime = 1; SET @j = 2;
WHILE @j * @j <= @i BEGIN IF @i % @j = 0 BEGIN SET @isPrime = 0; BREAK; END SET @j = @j + 1; END IF @isPrime = 1 BEGIN IF LEN(@result) > 0 SET @result = @result + '&' + CAST(@i AS VARCHAR(10)); ELSE SET @result = CAST(@i AS VARCHAR(10)); END SET @i = @i + 1;
END
SELECT @result AS prime_numbers;
Seems like cookies are disabled on this browser, please enable them to open this website
Print Prime Numbers
You are viewing a single comment's thread. Return to all comments →
DECLARE @n INT = 1000; DECLARE @i INT = 2; DECLARE @j INT; DECLARE @isPrime BIT; DECLARE @result VARCHAR(8000) = '';
WHILE @i <= @n BEGIN SET @isPrime = 1; SET @j = 2;
END
SELECT @result AS prime_numbers;