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

DECLARE SUB SORT (A() AS INTEGER, N%)
DECLARE FUNCTION DIFFERENCE% (A() AS INTEGER, N%)
DEFINT A-Z
DIM A0(5), A1(5), A2(5), A3(5), A4(5), A5(5)
DATA 0,0,0,0,0
FOR I = 0 TO 4: READ A0(I): NEXT I
DATA 1,1,1,1,1
FOR I = 0 TO 4: READ A1(I): NEXT I
DATA 0,1,1,1,1
FOR I = 0 TO 4: READ A2(I): NEXT I
DATA 0,0,1,1,2
FOR I = 0 TO 4: READ A3(I): NEXT I
DATA 0,1,2,3,4
FOR I = 0 TO 4: READ A4(I): NEXT I
DATA 1,2,3,4,5
FOR I = 0 TO 4: READ A5(I): NEXT I
PRINT "Количество разных чисел массиве A0 = ";
PRINT DIFFERENCE(A0(), 5)
PRINT "Количество разных чисел массиве A1 = ";
PRINT DIFFERENCE(A1(), 5)
PRINT "Количество разных чисел массиве A2 = ";
PRINT DIFFERENCE(A2(), 5)
PRINT "Количество разных чисел массиве A3 = ";
PRINT DIFFERENCE(A3(), 5)
PRINT "Количество разных чисел массиве A4 = ";
PRINT DIFFERENCE(A4(), 5)
PRINT "Количество разных чисел массиве A5 = ";
PRINT DIFFERENCE(A5(), 5)
END


FUNCTION DIFFERENCE (A() AS INTEGER, N%)
DEFINT A-Z
  FOR I = 0 TO N% - 1
    IF A(I) = 0 THEN K0 = 1: EXIT FOR
  NEXT I
  FOR I = 0 TO N% - 1
    IF A(I) <> 0 THEN
       FOR J = I + 1 TO N% - 1
         IF A(I) = A(J) THEN A(I) = 0: EXIT FOR
       NEXT J
    END IF
  NEXT I
  FOR I = 0 TO N% - 1
    IF A(I) <> 0 THEN M = M + 1
  NEXT I
  DIFFERENCE = M + K0
END FUNCTION