]>
Commit | Line | Data |
---|---|---|
5869c6ff XL |
1 | use std::io; |
2 | ||
74b04a01 XL |
3 | fn main() { |
4 | let a = [1, 2, 3, 4, 5]; | |
5869c6ff XL |
5 | |
6 | println!("Please enter an array index."); | |
7 | ||
8 | let mut index = String::new(); | |
9 | ||
10 | io::stdin() | |
11 | .read_line(&mut index) | |
12 | .expect("Failed to read line"); | |
13 | ||
14 | let index: usize = index | |
15 | .trim() | |
16 | .parse() | |
17 | .expect("Index entered was not a number"); | |
74b04a01 XL |
18 | |
19 | let element = a[index]; | |
20 | ||
04454e1e | 21 | println!("The value of the element at index {index} is: {element}"); |
74b04a01 | 22 | } |