[Solved] Print nubers 1, 3, 6, 10, 15, 21 from a given range using Kotlin [closed]


The numbers that you want to print are the first 6 members of the sequence:

a(n) = n * (n + 1) /2

So you could print them with this loop:

for (i: Int in 1..6) {
    println(i * (i + 1) / 2)
}

or:

(1..6).forEach { println(it * (it + 1) / 2) }

1

solved Print nubers 1, 3, 6, 10, 15, 21 from a given range using Kotlin [closed]