Заданы массивы A1, A2,…,A10 и C1, C2,…,C10 и число P. Построить ряд D, содержащий A(i) и C(i) меньше заданного P — QBasic(Бейсик)

CLS
n = 10
DIM a(n), c(n)
RANDOMIZE TIMER
FOR i = 1 TO n
    a(i) = INT(RND * 101) - 50
NEXT
FOR i = 1 TO n
    c(i) = INT(RND * 101) - 50
NEXT
PRINT "Massiv a(10)"
FOR i = 1 TO n
    PRINT a(i);
NEXT
PRINT: PRINT
PRINT "Massiv c(10)"
FOR i = 1 TO n
    PRINT c(i);
NEXT
PRINT: PRINT
INPUT "Vvedite chislo P="; p
PRINT
k = 0
FOR i = 1 TO n
    IF a(i) < p THEN k = k + 1
    IF c(i) < p THEN k = k + 1
NEXT i
IF k > 0 THEN
    DIM d(k)
    k = 0
    FOR i = 1 TO n
        IF a(i) < p THEN k = k + 1: d(k) = a(i)
        IF c(i) < p THEN k = k + 1: d(k) = c(i)
    NEXT i
    PRINT "Ryad d"; "("; k; ")"
    FOR i = 1 TO k
        PRINT d(i);
    NEXT i
ELSE
    PRINT "Vse elementi massiva a(10) i b(10)>"; p
END IF

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

Leave a Comment