Разработать блок схему и написать программу в QBASIC
Дан массив А из 20 элементов. Найти сумму отрицательных элементов массива.Результат вывести на печать
Answers & Comments
artem228artem DIM ch$(26) FOR i = 1 TO 26 ch$(i) = CHR$(ASC("a") + i - 1) NEXT
DIM cw(26) AS LONG
PRINT "text:" INPUT "", s$ DO WHILE s$ <> "*" s$ = s$ + " " iw = 0 FOR i = 1 TO LEN(s$) c$ = MID$(s$, i, 1) IF iw = 0 AND c$ <> " " THEN iw = 1 idx = ASC(c$) - ASC("a") + 1 cw(idx) = cw(idx) + 1 ELSEIF iw = 1 AND c$ = " " THEN iw = 0 END IF NEXT INPUT "", s$ LOOP
FOR i = 1 TO 25 m = i FOR j = i TO 26 IF cw(j) > cw(m) OR (cw(j) = cw(m) AND ch$(j) < ch$(m)) THEN m = j END IF NEXT IF m <> i THEN tmp = cw(m) cw(m) = cw(i) cw(i) = tmp tmp$ = ch$(m) ch$(m) = ch$(i) ch$(i) = tmp$ END IF NEXT
FOR i = 1 TO 26 IF cw(i) <> 0 THEN PRINT ch$(i) + ":"; cw(i) END IF NEXT
Answers & Comments
DIM ch$(26)
FOR i = 1 TO 26
ch$(i) = CHR$(ASC("a") + i - 1)
NEXT
DIM cw(26) AS LONG
PRINT "text:"
INPUT "", s$
DO WHILE s$ <> "*"
s$ = s$ + " "
iw = 0
FOR i = 1 TO LEN(s$)
c$ = MID$(s$, i, 1)
IF iw = 0 AND c$ <> " " THEN
iw = 1
idx = ASC(c$) - ASC("a") + 1
cw(idx) = cw(idx) + 1
ELSEIF iw = 1 AND c$ = " " THEN
iw = 0
END IF
NEXT
INPUT "", s$
LOOP
FOR i = 1 TO 25
m = i
FOR j = i TO 26
IF cw(j) > cw(m) OR (cw(j) = cw(m) AND ch$(j) < ch$(m)) THEN
m = j
END IF
NEXT
IF m <> i THEN
tmp = cw(m)
cw(m) = cw(i)
cw(i) = tmp
tmp$ = ch$(m)
ch$(m) = ch$(i)
ch$(i) = tmp$
END IF
NEXT
FOR i = 1 TO 26
IF cw(i) <> 0 THEN
PRINT ch$(i) + ":"; cw(i)
END IF
NEXT