Дан массив натуральных чисел. Найти сумму элементов,кратных данному K- QBasic(Бейсик)

1
2
3
4
5
6
7
8
9
10
11
12
13
cls
input n
dim a(n)
randomize timer
for i =1 to n
a(i)=int(rnd(1)*50 +1)
next i
input k
for i = 1 to n
? a(i);
if a(i)/k=0 then s=s+a(i)
next i
? s
1
2
3
4
5
6
7
8
9
10
11
12
13
cls
input n
dim a(n)
randomize timer
for i =1 to n
a(i)=int(rnd(1)*50 +1)
next i
input k
for i = 1 to n
? a(i);
IF a(i) MOD k=0 THEN s=s+a(i)
next i
? s

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

Leave a Comment