I tried to reverse array with recursion method but somehow my code didn't show the right output.
static void Main(string[] args)
{
int[] arr = { 10, 20, 15, 40, 70, 60, 50, 80, 90, 25 };
ReverseArray(arr, arr.Length);
string output = PrintArray(arr);
Console.WriteLine(output);
}
static void ReverseArray(int[] V, int N)
{
int start = V.Length - N;
if (N > 1)
{
int temp = V[start];
V[start] = V[N - 1];
V[N - 1] = temp;
ReverseArray(V, N - 1);
}
}
static string PrintArray(int[] arr)
{
string temp = "";
foreach (int angka in arr)
{
temp += angka.ToString() + " ";
}
return temp;
}
I want the output showing this : (25,90,80,50,60,70,40,15,20,10)
But my output is like this :
What's wrong with my code ?