From 9805ee1768611e86b45b7343ed3c58a5cc8a0982 Mon Sep 17 00:00:00 2001 From: kangshifu <42248685+leikang123@users.noreply.github.com> Date: Tue, 29 Aug 2023 16:15:26 +0800 Subject: [PATCH] feat: add array4.rs exercise --- exercises/array/array4.rs | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 exercises/array/array4.rs diff --git a/exercises/array/array4.rs b/exercises/array/array4.rs new file mode 100644 index 00000000..f8f4de27 --- /dev/null +++ b/exercises/array/array4.rs @@ -0,0 +1,27 @@ + +// array4.rs +// +// Here is the code for how the array learns + +// I AM NOT DONE + + + +fn main(){ + // define arrays a +let a =[1,2,3,4,5]; + println!("please enter an array index."); +let mut index = String::new(); + std::io::stdin() + .read_line(&mut index) + .expect("Fail to read line"); +let index :usize =index + .trim() + .parse() + .expect("index entered was not a number"); + +let element = a[index]; + println!("The value of is {} element : {}",index,element); + + } + \ No newline at end of file