Sum of squares
Rust Lambdas
closure |x| x * x
Flowchart (ISO 5807)
Source code
fn main() {
let square = |x: i32| x * x;
let mut total = 0;
for i in 1..=5 {
total += square(i);
}
println!("Сума квадратів: {}", total);
} closure |x| x * x
fn main() {
let square = |x: i32| x * x;
let mut total = 0;
for i in 1..=5 {
total += square(i);
}
println!("Сума квадратів: {}", total);
}