QBASIC program to print NEPAL, PAL, L | String Pattern Printing program

3 years ago

QBASIC Program to print the string pattern NEPAL, PAL, L. This pattern can be print using for loop with STEP 2 ans some string library functions as follows.                                                             

Simple Program

CLS
s$ = "NEPAL"
r = 1
t = 10
FOR i = 5 TO 1 STEP -2
    PRINT TAB(t); MID$(s$, r, i)
    r = r + 2
    t = t + 2
NEXT i
END

OUTPUT

N E P A L
    P A L
        L

Using SUB ... END SUB

DECLARE SUB pat(a$)
CLS
a$ = "NEPAL"
CALL pat(a$)
END

SUB pat (s$)
    r = 1
    t = 10
    FOR i = 5 TO 1 STEP -2
        PRINT TAB(t); MID$(s$, r, i)
        r = r + 2
        t = t + 2
    NEXT i
END SUB

Using FUNCTION ... END

DECLARE FUNCTION pat$(a$)
CLS
a$ = "NEPAL"
p$ = pat$(a$)
END

pat$ (s$)
    a$ = "NEPAL"
    r = 1
    t = 10
    FOR i = 5 TO 1 STEP -2
        PRINT TAB(t); MID$(s$, r, i)
        r = r + 2
        t = t + 2
    NEXT i
END FUNCTION
  3299