Вводится n, надо получить матрицу n*n, заполненную по диагоналям, например: — QBasic(Бейсик)

1 2 6
3 5 7
4 8 9
DECLARE SUB TakeFont ()
DECLARE SUB PrintCharXY (x%, y%, ASCII%, cv%)
DECLARE SUB PrintTextXY (x%, y%, Text$, cv%)
DECLARE SUB PrintMatrixXY (x%, y%, Matr() AS INTEGER, HorizR%, VertR%, HSpacing!, VSpacing!, cv%)
 
DIM SHARED Smb%(255, 15), TwoPOW%(7)
DIM M(10, 10) AS INTEGER, f%(10)
 
  SCREEN 13
  TakeFont
    LINE (0, 0)-(319, 199), 199, BF
  FOR i% = 25 TO 0 STEP -1
   PrintCharXY 0 + i% * 4, 20 + i% * 4, 65 + i%, 31 + (i% AND 15) + 1
  NEXT
 
  FOR iy% = 1 TO 10: FOR ix% = 1 TO 10: M(ix%, iy%) = RND * 10: NEXT: NEXT
  PrintTextXY 10, 10, "Proverka pechati matric!", 15
 
  PrintMatrixXY 90, 30, M(), 10, 10, 20, 10, 151
 
SUB PrintCharXY (x%, y%, ASCII%, cv%)
     FOR GY% = 0 TO 15
        FOR GX% = 0 TO 7
          IF (Smb%(ASCII%, GY%) AND TwoPOW%(GX%)) = TwoPOW%(GX%) THEN PSET (GX% + x%, GY% + y%), cv%
        NEXT
     NEXT
END SUB
 
SUB PrintMatrixXY (x%, y%, Matr() AS INTEGER, HorizR%, VertR%, HSpacing!, VSpacing!, cv%)
 DIM Zn$
  FOR iy% = 1 TO VertR%
     FOR ix% = 1 TO HorizR%
      Zn$ = STR$(Matr(ix%, iy%))
      PrintTextXY x% + ix% * HSpacing!, y% + iy% * VSpacing!, Zn$, cv%
     NEXT
  NEXT
END SUB
 
SUB PrintTextXY (x%, y%, Text$, cv%)
xn% = x%
IF Text$ = "" THEN EXIT SUB
  FOR xp% = 1 TO LEN(Text$)
    CH% = ASC(MID$(Text$, xp%, 1))
    PrintCharXY xn%, y%, CH%, cv%
    xn% = xn% + 8
  NEXT
END SUB
 
SUB TakeFont
  '  Таблица степеней двойки для скорости
  FOR i% = 0 TO 7: TwoPOW%(i%) = 2 ^ i%: NEXT
  '  Копируем побитно системный шрифт
  FOR i% = 0 TO 255
     LINE (0, 0)-(7, 15), 0, BF
     LOCATE 1, 1: PRINT CHR$(i%)
     FOR GY% = 0 TO 15
        ST% = 0
        FOR GX% = 0 TO 7
          IF POINT(GX%, GY%) = 15 THEN ST% = ST% + TwoPOW%(GX%)
        NEXT
        Smb%(i%, GY%) = ST%
     NEXT
  NEXT
END SUB

Тестирование выполнено в программе QB64 ( Скачать )

Leave a Comment