Sum of numbers

Report a typo

Choose the correct ways to find the sum of integer numbers in the numbers list.

a)

var sum = 0
for (num in numbers) {
    sum += num
}

b)

var sum = 0
for (i in numbers.indices) {
    sum += i
}

c)

var sum = 0

for (i in 1 until numbers.size) {
    sum += numbers[i]
}

d)

var sum = 0
for (i in numbers.lastIndex downTo 0) {
    sum += numbers[i] 
}
Select one or more options from the list
___

Create a free account to access the full topic