Menu
Coddy logo textTech

Edit Recap - Reversed Array

Part of the Fundamentals section of Coddy's C# journey — lesson 60 of 69.

challenge icon

Challenge

Easy

Write a method named Reverse which gets an array of numbers as argument and returns the reversed array.

For example, for [1, 2, 3], the expected output is [3, 2, 1].

Note: Using Array.Reverse() is not allowed. Implement the reversal manually using a loop.
Hint: To access elements from the end of the array, use the index pattern arr.Length - 1 - i.

Try it yourself

using System;

public class Program {
    public static int[] Reverse(int[] arr) {
        // Write your code below
       
    }

    public static void Main(string[] args) {
        string text = Console.ReadLine();
        string[] stringArr = text.Split(",");
        int[] arr = new int[stringArr.Length];
        for (int i = 0; i < stringArr.Length; i++) {
            arr[i] = int.Parse(stringArr[i]);
        }
        
        int[] result = Reverse(arr);
        Console.WriteLine("The reversed array is: " + string.Join(", ", result));
    }
}

All lessons in Fundamentals