We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
declare @a as int=1
while @a <= 20
begin
print replicate ('*',@a)
set @a=@a+1
end
**2nd Way
**
WITH Numbers AS (
SELECT 1 AS n
UNION ALL
SELECT n + 1 FROM Numbers WHERE n < 20
)
SELECT REPLICATE('* ', n) AS pattern
FROM Numbers
OPTION (MAXRECURSION 20);
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Draw The Triangle 2
You are viewing a single comment's thread. Return to all comments →
declare @a as int=1 while @a <= 20 begin print replicate ('*',@a) set @a=@a+1 end
**2nd Way ** WITH Numbers AS ( SELECT 1 AS n UNION ALL SELECT n + 1 FROM Numbers WHERE n < 20 ) SELECT REPLICATE('* ', n) AS pattern FROM Numbers OPTION (MAXRECURSION 20);