- 1

Make a program that take N as input and calculates the sum of all consecutive number from 1 to N inclusive.

You can iterate over a range and calculate the sum of all numbers in the range. Remember, range(a, b) does not include b, thus you need to use b+1 to include b in the range.

11th Sep 2021, 7:32 PM
elly paul
elly paul - avatar
2 Antworten
+ 3
elly paul Your code please?
11th Sep 2021, 7:39 PM
A͢J
A͢J - avatar
0
fun main() { var n = readLine()!!.toInt() print((1..n).asSequence().sum()) }
11th Sep 2021, 11:19 PM
Coding Cat
Coding Cat - avatar