The source code to find out the first repeated element in the array is given below. The given program is compiled and executed successfully.
// Rust program to find out the first repeated
// element in the array
fn main()
{
let mut arr:[usize;6] = [0,1,2,3,2,3];
let mut i:usize=0;
let mut j:usize=0;
let mut item:usize=0;
let mut flag:isize=0;
while i<5
{
j=i;
while j<=5
{
if arr[i] == arr[j] {
item = arr[j];
flag = 1;
break;
}
j=j+1;
}
i=i+1;
}
if flag == 1 {
println!("{0} repeated @ {1} index", item, j)
}
else {
println!("There is no repeated element")
}
}
Output:
2 repeated @ 4 index
Explanation:
Here, we created an array of integers with 6 elements, and then we searched the 1st repeated element in the array and printed the index of repeated elements.
Program/Source Code:
The source code to find out the first repeated element in the array is given below. The given program is compiled and executed successfully.
Output:
Explanation:
Here, we created an array of integers with 6 elements, and then we searched the 1st repeated element in the array and printed the index of repeated elements.
need an explanation for this answer? contact us directly to get an explanation for this answer