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

    QBASIC Pattern Printing Program (SUB ... END SUB | FUNCTION ... END FUNCTION)

    Posted on 2021-02-26

    This pattern printing method is different then other patterns. We cna see that the strings of patterns are printing from the middle 7 string. It is giving us the illusion of adding * symbol before and after the string 'NEPAL'. To print this pattern we need to read the middle 7 characters in first loop. After that we print extra * symbols before and after.

    *NEPAL*

    **NEPAL**

    ***NEPAL***

    ****NEPAL****

    *****NEPAL*****

    CLS
    s$ = "*****NEPAL*****"
    c = 7
    b = 35
    FOR i = 5 TO 1 STEP -1
        PRINT TAB(b); MID$(s$, i, c)
        c = c + 2
        b = b - 1
    NEXT i
    END

    Using SUB ... END SUB

    DECLARE SUB pattern(s$)
    CLS
    s$ = "*****NEPAL*****"
    CALL pattern(s$)
    END
    
    SUB pattern (s$)
      c = 7
      b = 35
      FOR i = 5 TO 1 STEP -1
        PRINT TAB(b); MID$(s$, i, c)
        c = c + 2
        b = b - 1
      NEXT i
    END SUB
    

     

    Using SUB ... END SUB

    DECLARE FUNCTION pattern()
    CLS
    p = pattern
    END
    
    FUNCTION pattern ()
      s$ = "*****NEPAL*****"
      c = 7
      b = 35
      FOR i = 5 TO 1 STEP -1
         PRINT TAB(b); MID$(s$, i, c)
         c = c + 2
         b = b - 1
      NEXT i
    END FUNCTION
    

    304