Menu
Coddy logo textTech

Recap - Sigma Function

Part of the Fundamentals section of Coddy's Rust journey — lesson 53 of 75.

challenge icon

Challenge

Easy

Write a function named sigma with one argument that represents a number n.

The function will return the sum of all the numbers from 1 to n (including).

For example, for sigma(5), the function will return 15, because 15 = 1 + 2 + 3 + 4 + 5.

Try it yourself

use std::io;

fn sigma(n: i32) -> i32 {
    // Write your code below
}

fn main() {
    let mut input = String::new();
    io::stdin().read_line(&mut input).unwrap();
    let n: i32 = input.trim().parse().unwrap();
    let res = sigma(n);
    println!("{}", res);
}

All lessons in Fundamentals