The source code to compare two arrays using the equal to (==) operator is given below. The given program is compiled and executed successfully.
// Rust program to compare two arrays
// using the equal to (==) operator
fn main() {
let mut arr1:[i32;5] = [1,2,3,4,5];
let mut arr2:[i32;5] = [1,2,3,4,5];
let mut arr3:[i32;5] = [5,4,3,2,1];
if(arr1==arr2)
{
println!("arr1 and arr2 have similar elements");
}
else
{
println!("arr1 and arr2 does not have similar elements");
}
if(arr1==arr3)
{
println!("arr1 and arr3 have similar elements");
}
else
{
println!("arr1 and arr3 does not have similar elements");
}
}
Output:
arr1 and arr2 have similar elements
arr1 and arr3 does not have similar elements
Explanation:
Here, we created three integer arrays, each of them containing 5 elements. Then we compared arrays using equal to (==) operator and printed the appropriate message.
Program/Source Code:
The source code to compare two arrays using the equal to (==) operator is given below. The given program is compiled and executed successfully.
Output:
Explanation:
Here, we created three integer arrays, each of them containing 5 elements. Then we compared arrays using equal to (==) operator and printed the appropriate message.
need an explanation for this answer? contact us directly to get an explanation for this answer