Найти сумму элементов в каждой строке матрицы между наибольшим её элементом и наименьшим. Использовать подпрограмму — QBasic(Бейсик)

DECLARE SUB proc (b!(), str AS INTEGER)
CLS
CONST n = 8
CONST m = 7
DIM a(n, m) AS SINGLE
DIM i AS INTEGER
DIM j AS INTEGER
RANDOMIZE TIMER
FOR i = 1 TO n
    FOR j = 1 TO m
        a(i, j) = RND * 101 - 50
    NEXT j
NEXT i
FOR i = 1 TO n
    FOR j = 1 TO m
        PRINT a(i, j);
    NEXT j
    PRINT
NEXT i
FOR i = 1 TO n
    CALL proc(a(), i)
NEXT

SUB proc (b(), str AS INTEGER)
s = 0: max = b(str, 1): min = b(str, 1): jmax = 1: jmin = 1
FOR j = 2 TO m
    IF b(str, j) > max THEN max = b(str, j): jmax = j
    IF b(str, j) < min THEN min = b(str, j): jmin = j
NEXT
IF jmin > jmax THEN
    FOR j = jmax TO jmin
        s = s + b(str, j)
    NEXT
ELSE
    FOR j = jmin TO jmax
        s = s + b(str, j)
    NEXT
END IF
PRINT
PRINT "maks element stroki #"; str; "="; max;
PRINT " koordinati("; str; ","; jmax; ")"
PRINT "min element stroki #"; str; "="; min;
PRINT " koordinati("; str; ","; jmin; ")"
PRINT "Summa elementov mezhdu maks i min stroki #"; str; "="; s
END SUB

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

Leave a Comment