QBASIC Program to print the pattern 1, 12, 123, 1234, 12345

3 years ago

QBASIC Progrma to print the following pattern 1, 12, 123, 1234, 12345. Nested loop pattern printing program in qbasic. 

Solution: 

Simple Program                                                                                        

CLS
FOR i = 1 TO 5
    FOR j = 1 TO i
        PRINT j;
    NEXT j
    PRINT
NEXT i
END

Output

1
1 2
1 2 3
1 2 3 4
1 2 3 4 5

 

Using SUB ... END SUB

DECLARE SUB Pattern()_
CLS
CALL Pattern
END

SUB Pattern ()
    FOR i = 1 TO 5
        FOR j = 1 TO i
            PRINT j;
        NEXT j
        PRINT
    NEXT i
END SUB

 

Using FUNCTION ... END FUNCTION

DECLARE FUNCTION Pattern()_
CLS
r = Pattern
END

FUNCTION Pattern ()
    FOR i = 1 TO 5
        FOR j = 1 TO i
            PRINT j;
        NEXT j
        PRINT
    NEXT i
END FUNCTION
  9914
Please Login to Post a Comment