Star Pattern (Pyramid) program in QBASIC (Using SUB/FUNCTION)
4 months ago
The Pyramid pattern is a classic geometric design that resembles the shape of an ancient pyramid, with each layer having an incremental number of stars. To create this beautiful pattern in QBASIC, we will harness the power of SUB and FUNCTION procedures, breaking down the complex structure into manageable components.
CLS
x$ = "*********"
b = 1
t = 20
FOR i = LEN(x$) TO 1 STEP -2
PRINT TAB(t); MID$(x$, b, i)
b = b + 1
t = t + 1
NEXT i
END
Using SUB Procedure
DECLARE SUB pattern(x$)
CLS
x$ = "*********"
CALL pattern(x$)
END
SUB pattern (x$)
b = 1
t = 20
FOR i = LEN(x$) TO 1 STEP -2
PRINT TAB(t); MID$(x$, b, i)
b = b + 1
t = t + 1
NEXT i
END SUB
Using FUNCTION Procedure
DECLARE FUNCTION pattern()
CLS
p = pattern(x$)
END
FUNCTION pattern (x$)
x$ = "*********"
b = 1
t = 20
FOR i = LEN(x$) TO 1 STEP -2
PRINT TAB(t); MID$(x$, b, i)
b = b + 1
t = t + 1
NEXT i
END FUNCTION
529