|
Reversing the elements of an array please help?
Reversing the elements of an array involves swapping the corresponding elements of the array: the first with the last, the second with the next to the last, and so on, all the way to the middle of the array.
This is what i got but its not working. It compiles but wont change the contents of the array
using namespace std;
int main()
{
int score[10] = {10, 20, 30, 40, 50, 60, 70, 80, 90, 100};
for(int k = 0; k < 10; k++)
{
int temp = score[k]; // store the first element value in temp
score[k] = score[9-k]; // store the last element value in the first element
score[9-k] = temp; // store temp in the last element
}
return 0;
}
|