Home QBASIC C Java HTML
  • More Courses
  • MCQs
  • Blog Download
  • Tools
  • Contact

    QBASIC Program to print 54321, 4321, 321, 21, 1

    Posted on 2021-01-29

    QBASIC Program to print the pattern 54321, 4321, 321, 21, 1. Nested for loop pattern printing example in qbasic programming. 

    Solution: 

    Simple Program                                                                                                    

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

    Output

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

    Using SUB ... END SUB

     
    DECLARE SUB Pattern()_
    CLS
    CALL Pattern
    END
    
    SUB Pattern ()
        CLS
        FOR i = 5 TO 1 STEP -1
        FOR j = 1 TO i STEP 1
            PRINT j;
        NEXT j
        PRINT
    NEXT i
    END
    END SUB
    

    Using FUNCTION ... END FUNCTION

     
    DECLARE FUNCTION Pattern()_
    CLS
    r = Pattern
    END
    
    FUNCTION Pattern ()
        CLS
        FOR i = 5 TO 1 STEP -1
        FOR j = 1 TO i STEP 1
            PRINT j;
        NEXT j
        PRINT
    NEXT i
    END
    END FUNCTION
    

    826