I'm attempting to reverse an array of integers.
I think my code's function is accurate, but I can't seem to achieve the right result.
The result is written as 10 9 8 7 6.
Why am I unable to obtain the second half of the numbers?
The output is as follows when I delete the "/2" from count: 10 9 8 7 6 6 7 8 9 10
void reverse(int [], int);
int main ()
{
const int SIZE = 10;
int arr [SIZE] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
reverse(arr, SIZE);
return 0;
}
void reverse(int arr[], int count)
{
int temp;
for (int i = 0; i < count/2; ++i)
{
arr[i] = temp;
temp = arr[count-i-1];
arr[count-i-1] = arr[i];
arr[i] = temp;
cout << temp << " ";
}
}