Home »
Rust »
Rust Programs
Rust program to reverse an array
Rust | Array Example: Write a program to reverse an array.
Submitted by Nidhi, on October 20, 2021
Problem Solution:
In this program, we will create an array of integer elements then we will reverse the array using the reverse() function.
Program/Source Code:
The source code to reverse an array is given below. The given program is compiled and executed successfully.
// Rust program to reverse an array
fn main()
{
let mut arr:[i32;5] = [0,1,2,3,4];
println!("Array: {:?}",arr);
arr.reverse();
println!("Reversed Array: {:?}",arr);
}
Output:
Array: [0, 1, 2, 3, 4]
Reversed Array: [4, 3, 2, 1, 0]
Explanation:
Here, we created an array of integers with 5 elements and then we reversed created array using the reverse() function. After that, we printed reversed array.
Rust Arrays Programs »