Menu
Coddy logo textTech

Recap - Sigma Method

Part of the Fundamentals section of Coddy's Ruby journey — lesson 51 of 88.

challenge icon

Challenge

Easy

Define a method called sigma that takes one parameter n and returns the sum of all integers from 1 to n.

Read an integer from input and use your sigma method to calculate and print the result.

For example, if the input is 4:

  • The sum is 1 + 2 + 3 + 4 = 10

The output should be:

10

If the input is 6, the output should be:

21

If the input is 1, the output should be:

1

Try it yourself

# Read input
n = gets.to_i

# TODO: Define your sigma method below


# Call the method and print the result
puts sigma(n)

All lessons in Fundamentals