Calculate the sum of natural numbers up to a given limit

Report a typo

Write a Kotlin program that finds the sum of the natural numbers up to a given number. You'll receive an integer 'N' as input, representing the limit of the numbers to be added. Your program should print the calculated sum as the output.

Sample Input 1:

10

Sample Output 1:

55

Sample Input 2:

100

Sample Output 2:

5050
Write a program in Kotlin
// Import necessary Kotlin libraries
import java.util.*

fun main(args: Array<String>) {
// Create a scanner object for getting input
val scanner = Scanner(System.`in`)

// Read the input number
val N = scanner.nextInt()

// Variable to store the sum
var sum = 0

// Write a repeat loop here to add the numbers from 1 to N to the sum variable

// Output the sum
println(sum)
}

Create a free account to access the full topic