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.
Draw The Triangle 1
Draw The Triangle 1
Sort by
recency
|
1107 Discussions
|
Please Login in order to post a comment
DECLARE @i INT = 20 WHILE (@i > 0) BEGIN PRINT REPLICATE('* ', @i) SET @i = @i - 1 END GIVES THE ANSWER
PLsql: set serveroutput on; DECLARE v_row NUMBER := 20; v_col NUMBER; BEGIN FOR i IN REVERSE 1..v_row LOOP v_col := i; FOR j IN 1..v_col LOOP DBMS_OUTPUT.PUT('* '); END LOOP; DBMS_OUTPUT.PUT_LINE(''); END LOOP; END; /
I created a query to give me the numbers 0 through 9 and then joined it back to itself to give me a list of numbers. Then, I used that number int eh replicate() function to generate the appropriate number of astrics.
SQL
with recursive cnt(val) as ( select 20 as val union select val -1 from cnt where val > 1 ) select REPEAT('* ', val) from cnt;