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


DECLARE SUB NEXTPOINT (X&, Y&)
  DIM nDiag AS LONG   'номер диагонали
  DIM xBeg AS LONG, yBeg AS LONG 'начальная точка на диагонали
  DIM nPoints AS LONG 'количество точек на диагонали
  DIM nBeg AS LONG    'номер начальной точки на диагонали
  DIM dx(8), dy(8)
  DATA -1,-1,-1,0,1,1, 1, 0
  FOR J = 0 TO 7: READ dx(J): NEXT J
  DATA -1, 0, 1,1,1,0,-1,-1
  FOR J = 0 TO 7: READ dy(J): NEXT J
m1:
  CLS
  INPUT "Введите номер точки: ", N
REM Определение параметров диагонали
  nBeg = 0: M = N: xBeg = 0: yBeg = 0
  FOR k = 0 TO 200000000
    M = M - k
    IF M < 0 THEN EXIT FOR
    nBeg = nBeg + k
  NEXT k
  nDiag = k - 1: nPoints = k
  IF (nDiag MOD 2) = 0 THEN 'диагональ с четным номером
      yBeg = nDiag
      xN = xBeg + (N - nBeg)
      yN = yBeg - (N - nBeg)
  ELSE                     'диагональ с нечетным номером
      xBeg = nDiag
      xN = xBeg - (N - nBeg)
      yN = yBeg + (N - nBeg)
  END IF
  PRINT "Номера смежных точек: "
  FOR k = 0 TO 7
      X& = xN + dx(k)
      Y& = yN + dy(k)
      NEXTPOINT X&, Y&
  NEXT k
  PRINT
  PRINT "Хотите повторить - (y/n) : ";
m2:
  A$ = INKEY$: IF A$ = "" THEN GOTO m2
  IF A$ = "y" THEN GOTO m1
END

SUB NEXTPOINT (X&, Y&)
  SHARED nDiag AS LONG, xBeg AS LONG, yBeg  AS LONG, nPoints  AS LONG
  DIM N AS LONG, J AS INTEGER
  IF X& < 0 OR Y& < 0 THEN EXIT SUB
  nBeg = 0: nDiag = X& + Y&: xBeg = yBeg = 0
  nPoints = nDiag + 1
  FOR J = 0 TO nPoints - 1: nBeg = nBeg + J: NEXT J
  IF (nDiag MOD 2) = 0 THEN
      yBeg = nDiag: N = nBeg + yBeg - Y&
  ELSE
      xBeg = nDiag: N = nBeg + xBeg - X&
  END IF
  PRINT N; ",";
END SUB