You are viewing a single comment's thread. Return to all comments →
Took a way more computationally expensive path here, but still works. Learned quite a bit from the other solutions below.
DECLARE @n AS INT = 2 DECLARE @s AS VARCHAR(1000) = '' WHILE @n < 1000 BEGIN DECLARE @m AS INT = @n - 1, @p AS INT = 1 WHILE @m >= 2 AND @p = 1 BEGIN IF @n % @m <> 0 SET @m = @m - 1 ELSE SET @p = 0 END IF @p = 1 AND @n > 2 SET @s = @s + '&' + CAST(@n AS VARCHAR(4)) ELSE IF @p = 1 SET @s = @s + CAST(@n AS VARCHAR(4)) SET @n = @n + 1 END PRINT @s
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 →
Took a way more computationally expensive path here, but still works. Learned quite a bit from the other solutions below.