You are viewing a single comment's thread. Return to all comments →
solution in ms sql (without recursive, For Dummies :D)
DECLARE @counter INT; DECLARE @numbers VARCHAR(700) = '2&3'; DECLARE @my_number INT = 4; DECLARE @your_number INT = 1000; -- Specify the upper limit here WHILE @my_number <= @your_number BEGIN SET @counter = 2; DECLARE @is_prime BIT = 1; -- Flag variable WHILE @counter < @my_number BEGIN IF @my_number % @counter = 0 BEGIN SET @is_prime = 0; -- Set flag to indicate not prime BREAK; -- Break out of the inner loop END; SET @counter = @counter + 1; END; IF @is_prime = 1 BEGIN SET @numbers = CONCAT(@numbers, '&', @my_number); END; SET @my_number = @my_number + 1; END; SELECT @numbers AS 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 →
solution in ms sql (without recursive, For Dummies :D)