You are viewing a single comment's thread. Return to all comments →
DECLARE @end INT = 1000 DECLARE @START INT = 2 DECLARE @counter INT DECLARE @value INT DECLARE @output VARCHAR(MAX) = ' '
WHILE @start <= @end BEGIN SET @counter = 2 SET @value = 1 WHILE @counter <= SQRT(@start) BEGIN IF @start%@counter = 0 BEGIN SET @value = 0 BREAK END SET @counter += 1 END IF @value = 1 AND @start >1 SET @output += CAST(@start AS VARCHAR(10))+ '&' SET @start += 1 END IF RIGHT(@output, 1) = '&' SET @output = LEFT(@output, LEN(@output) - 1)
PRINT @output
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 @end INT = 1000 DECLARE @START INT = 2 DECLARE @counter INT DECLARE @value INT DECLARE @output VARCHAR(MAX) = ' '
WHILE @start <= @end BEGIN SET @counter = 2 SET @value = 1 WHILE @counter <= SQRT(@start) BEGIN IF @start%@counter = 0 BEGIN SET @value = 0 BREAK END SET @counter += 1 END IF @value = 1 AND @start >1 SET @output += CAST(@start AS VARCHAR(10))+ '&' SET @start += 1 END IF RIGHT(@output, 1) = '&' SET @output = LEFT(@output, LEN(@output) - 1)
PRINT @output