Menu
Coddy logo textTech

Recap - Sigma Function

Part of the Fundamentals section of Coddy's Kotlin journey. Lesson 61 of 93.

challenge icon

Challenge

Medium

Write a function sigma that takes n and returns the sum of all integers from 1 to n.

Use a loop to accumulate the sum of each integer in the range.

Parameters:

  • n (Int): A positive integer representing the upper limit

Returns: The sum of all integers from 1 to n (Int)

Try it yourself

fun sigma(n: Int): Int {
    // Write code here
}

All lessons in Fundamentals

Practice on your own: Kotlin playground