You are viewing a single comment's thread. Return to all comments →
DECLARE @i INT =2; DECLARE @max INT =1000; DECLARE @sqrt DECIMAL (10,4)= 0; DECLARE @wholenum INT = 0; DECLARE @j INT =2; DECLARE @isPrime BIT; DECLARE @output VARCHAR(MAX)='' WHILE @i <= @max BEGIN SET @sqrt= SQRT(@i) SET @wholenum= FLOOR(@sqrt) SET @isPrime = 1 WHILE @j <=@wholenum BEGIN IF @i % @j = 0 BEGIN SET @isPrime = 0 BREAK; END SET @j= @j+1 END IF @isPrime = 1 BEGIN IF LEN(@output) > 0 SET @output = @output + '&' + CAST(@i AS VARCHAR); ELSE SET @output = CAST(@i AS VARCHAR); END SET @i = @i+1 SET @j=2 END 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 →
MS SQL Server