I get:
1
2 2
3 3 3
4 4 4 4
Output should be:
1
2 2
3 3 3
4 4 4 4
Codes:
SET SERVEROUTPUT ON SIZE 1000000
DECLARE
i NUMBER;
j NUMBER;
total_lines NUMBER := 4; -- Number of lines for the pyramid
leading_ spaces NUMBER;
line_output VARCHAR2(100); -- Variable to hold each line's output
BEGIN
-- Loop through each line to create the pyramid
FOR i IN 1..total_lines LOOP
-- Calculate leading spaces for centering the line
leading_spaces := total_lines - i;
-- Initialize the line output with leading spaces
line_output := LPAD(' ', leading_spaces);
-- Append numbers to the line output
FOR j IN 1..i LOOP
line_output := line_output || i || ' ';
END LOOP;
-- Print the line output
DBMS_OUTPUT.PUT_LINE(line_output);
END LOOP;
END;
/
the codes do not give the correct output but:
1
2 2
3 3 3
4 4 4 4
PL/SQL procedure successfully completed.
SQL>
Instead of
1
2 2
3 3 3
4 4 4 4
It should be:
1
2 2
3 3 3
4 4 4 4
Any help,
Thanks,
Fabrice
New contributor
Fabrice Joey THIBAUT is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.