You are viewing a single comment's thread. Return to all comments →
MS SQL Server solution:
DECLARE @N INT = 1001; WITH Numbers AS ( SELECT 2 AS num UNION ALL SELECT num + 1 FROM Numbers WHERE num + 1 <= @N ), Primes AS ( SELECT num FROM Numbers n WHERE NOT EXISTS ( SELECT 1 FROM Numbers d WHERE d.num < n.num AND d.num > 1 AND n.num % d.num = 0 ) ) SELECT STRING_AGG(CAST(num AS VARCHAR), '&') AS primes FROM Primes OPTION (MAXRECURSION 0);
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 solution: