ADVERTISEMENT
ADVERTISEMENT

Rust program to compare two arrays using the equal to (==) operator

Rust | Array Example: Write a program to compare two arrays using the equal to (==) operator.
Submitted by Nidhi, on October 20, 2021

Problem Solution:

In this program, we will create three integer arrays with few elements and then we will compare arrays using equal to (==) operator.

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.

// 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.

Rust Arrays Programs »



ADVERTISEMENT
ADVERTISEMENT


Comments and Discussions!



ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT

Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates

© https://www.includehelp.com some rights reserved.