Написать программу, реализующий магический квадрат — QBasic(Бейсик)

CLS
INPUT "Razmer storony matrici:", n
DIM KV(n, n), s, f
' Vvodim el-ti matritsi

FOR iy = 1 TO n: FOR ix = 1 TO n
        LOCATE 10, 5: PRINT "Vvedite element(goriz:" + STR$(ix) + "  vert:" + STR$(iy) + ")"
        PRINT SPACE$(80): LOCATE CSRLIN - 1, 1: INPUT a
        KV(iy, ix) = a
NEXT: NEXT
' Proveryaem na "volshebnost")))
FOR i = 1 TO n: s = s + KV(i, 1): NEXT
' Stroki&stolbtsi
FOR iy = 1 TO n: a = 0
    FOR ix = 1 TO n
        a = a + KV(iy, ix)
    NEXT
    IF a <> s THEN f = 1
NEXT
FOR ix = 1 TO n: a = 0
    FOR iy = 1 TO n
        a = a + KV(iy, ix)
    NEXT
    IF a <> s THEN f = 1
NEXT
' Diagonali
a = 0
FOR i = 1 TO n
    a = a + KV(i, i)
NEXT: IF a <> s THEN f = 1
a = 0
FOR i = 1 TO n
    a = a + KV((n - i) + 1, i)
NEXT: IF a <> s THEN f = 1
' Vivodim rezultat
LOCATE 2, 1
IF f = 0 THEN
    COLOR 10: PRINT "Magicheskij kvadrat"
ELSE
    COLOR 12: PRINT "Ne magicheskij kvadrat"
END IF
COLOR 7

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

Leave a Comment