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

    QBASIC Pattern printing program 5, 54, 543, 5432, 54321

    Posted on 2021-01-28

    Write a qbasic program to print the pattern 5, 54, 543, 5432, 54321. 

    Solution:                                                                                                      

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

     

    OUTPUT

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

     

    Using SUB ... END SUB

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

     

    Using FUNCTION ... END

    DECLARE FUNCTION pattern()
    CLS
    c = pattern
    END
    
    FUNCTION pattern ()
        FOR i = 5 TO 1 STEP -1
            FOR j = 5 TO i STEP -1
                PRINT j;
            NEXT j
            PRINT
        NEXT i
    END FUNCTION
    

    636