CREATE PROC USP_PRINT_TRIANGLE(@NO INT)
AS
BEGIN
DECLARE @I INT=1
DECLARE @J INT=9
DECLARE @STR VARCHAR(20)=''
WHILE(@I<=@NO)
BEGIN
SET @STR=@STR+CAST(@I AS VARCHAR(20))
PRINT SPACE(@J)+@STR
SET @I=@I+1
SET @J=@J-1
END
END
EXEC USP_PRINT_TRIANGLE 5
OUTPUT
1
1 2
1 2 3
1 2 3 4
1 2 3 4 5
CREATE PROC USP_PRINT_TRIANGLE(@NO INT)
AS
BEGIN
DECLARE @I INT=1
DECLARE @STR VARCHAR(20)=''
WHILE(@I<=@NO)
BEGIN
SET @STR=@STR+CAST(@I AS VARCHAR(20))
PRINT @STR
SET @I=@I+1
END
END
EXEC USP_PRINT_TRIANGLE 5
OUTPUT
1
1 2
1 2 3
1 2 3 4
1 2 3 4 5
AS
BEGIN
DECLARE @I INT=1
DECLARE @J INT=9
DECLARE @STR VARCHAR(20)=''
WHILE(@I<=@NO)
BEGIN
SET @STR=@STR+CAST(@I AS VARCHAR(20))
PRINT SPACE(@J)+@STR
SET @I=@I+1
SET @J=@J-1
END
END
EXEC USP_PRINT_TRIANGLE 5
OUTPUT
1
1 2
1 2 3
1 2 3 4
1 2 3 4 5
CREATE PROC USP_PRINT_TRIANGLE(@NO INT)
AS
BEGIN
DECLARE @I INT=1
DECLARE @STR VARCHAR(20)=''
WHILE(@I<=@NO)
BEGIN
SET @STR=@STR+CAST(@I AS VARCHAR(20))
PRINT @STR
SET @I=@I+1
END
END
EXEC USP_PRINT_TRIANGLE 5
OUTPUT
1
1 2
1 2 3
1 2 3 4
1 2 3 4 5
No comments:
Post a Comment