Kotlin Program to print the sum of first 10 natural numbers


In this program, You will learn how to print the sum of the first 10 natural numbers in Kotlin.


55 = 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10

Example: How to print the sum of the first 10 natural numbers in Kotlin.

import java.util.Scanner

fun main(args: Array<String>) {

    var s = 0

    for (i in 1..10) {
        s += i
    }

    println("Sum of first 10 natural numbers:$s")
}

Output:

Sum of first 10 natural numbers:55