There are no errors while compiling, but when execute i've got this:
cargo clean && cargo run
Compiling exercise1 v0.1.0 (/home/eyegor/mytmp/rust/misc/exercise1)
Finished dev [unoptimized + debuginfo] target(s) in 0.28s
Running `target/debug/exercise1`
thread 'main' panicked at 'index out of bounds: the len is 7 but the index is 7', /rustc/4560ea788cb760f0a34127156c78e2552949f734/src/libcore/slice/mod.rs:2717:10
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace.
my code:
fn main() {
let v:Vec<u8> = vec![1,2,3,6,7,8,9];
let a = exercise1(v);
println!("average - {}, middle - {}, max.count data - {}",a[0],a[1],a[2])
}
pub fn exercise1(v: Vec<u8>) -> [u8; 3] {
let mut i=0;
let mut b: u8 = v[0];
let mut a: [u8; 3]=[0,0,0];
for _k in &v {
i=i+1;
b=b+v[i];
}
a[0]=b/i as u8;
return a;
}