Примеры программ на языке QBASIC

DECLARE SUB USER ()
DECLARE SUB START ()
DECLARE SUB COMPUTER ()
DECLARE SUB PRINTXOD (col%, msg$)
  DEFINT A-Z
  DIM SHARED N
  DIM SHARED B AS INTEGER, S AS INTEGER, M AS INTEGER, Q AS INTEGER
  N = 5: Q = 12
  DIM SHARED A(N) AS INTEGER, I AS INTEGER, J AS INTEGER, K AS INTEGER
  M = 1
  START
m1:
  USER
  COMPUTER
  GOTO m1
END

SUB COMPUTER
  S = 0
  FOR I = 0 TO K - 1: S = S XOR A(I): NEXT I
  IF S = 0 THEN
    J = 0: S = A(0)
    FOR I = 1 TO K - 1
      IF S < A(I) THEN S = A(I): J = I
      B = 1
    NEXT I
  ELSE
    FOR J = 0 TO K - 1
      B = A(J) - (A(J) XOR S)
      IF B >= 0 THEN EXIT FOR
     NEXT J
  END IF
  A(J) = A(J) - B
  PRINTXOD 4, "Победил компьютер"
END SUB

SUB PRINTXOD (col%, msg$)
  COLOR col%, 0
  FOR I = 0 TO K - 1
    LOCATE M + 1, 3 * I + 1: PRINT USING "###"; A(I)
  NEXT I
  M = M + 1: IF M >= 23 THEN CLS : M = 2: PRINTXOD col%, msg$
  S = 0
  FOR J = 0 TO K - 1: S = S + A(J): NEXT J
  IF S <> 0 THEN EXIT SUB
  LOCATE M, 2: PRINT msg$
  SLEEP
  STOP
END SUB

SUB START
  CLS : RANDOMIZE (VAL(RIGHT$(TIME$, 2)))
  K = INT(RND * (N - 3)) + 3: ' число кучек
  FOR I = 0 TO K - 1
    A(I) = INT(RND * Q) + 1
  NEXT I
  LOCATE 1, 2: PRINT "Начало игры"
  PRINTXOD 4, ""
END SUB

SUB USER
  COLOR 2, 0
  LOCATE M - 1, 20
  PRINT "Ваш ход (кучка - сколько берем):"
M2:
  LOCATE M, 29:    PRINT "  "
  LOCATE M, 29:    INPUT J
  IF (J < 1) OR (J > K) OR (A(J - 1) = 0) THEN GOTO M2
m3:
  LOCATE M, 35:   PRINT "-  "
  LOCATE M, 37:   INPUT B
  IF (B < 1) OR (B > A(J - 1)) THEN GOTO m3
  A(J - 1) = A(J - 1) - B
  PRINTXOD 2, "Вы победили"
END SUB