Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR RUST

sum all elements of array rust

//Iterator::sum was stabilized in Rust 1.11.0. You can get an iterator from
//your array/slice/Vec and then use sum:

fn main() {
    let a = [1, 2, 3, 4, 5];
    let sum: u8 = a.iter().sum();
    println!("the total sum is: {}", sum);
}
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #sum #elements #array #rust
ADD COMMENT
Topic
Name
8+8 =