In this HackerRank Draw, The Triangle 1 problem solution P(R) represents a pattern drawn by Julia in R rows. The following pattern represents P(5):
* * * * *
* * * *
* * *
* *
*
Write a query to print the pattern P(20).
Problem solution MS SQL.
/* Enter your query here. Please append a semicolon ";" at the end of the query and enter your query in a single line to avoid error. */ DECLARE @cnt INT = 20; DECLARE @cnt2 INT = 0; DECLARE @st varchar(60) = ''
Problem solution in Oracle.
WHILE @cnt != 0
BEGIN
WHILE @cnt2 != @cnt
BEGIN
set @st = @st + ' *'
set @cnt2 = @cnt2 + 1;
END
PRINT @st;
SET @st = ''
SEt @cnt2 = 0
SET @cnt = @cnt - 1;
END;
Problem solution in DB2.
select rpad('*',level*2, ' *')
from dual
connect by level <= 20
order by level desc;

0 Comments