Asked by ola
Write a C++ program to fill an array with 6 numbers, and then reverse the values of this array.
Note: By using a function with two parameters with the name of the array and the size of this array.
Answers
Answered by
MathMate
If you need to interchange the values contained in two array element, you need to have a temporary storage.
Assuming the array contains integers ("numbrs"), it would look something like this:
int ar[6];
.... read in values to ar[0] - ar[5].
...
exchange(ar,6);
...
void exchange{int ar[], int nar){
int tmp,i;
for(i=0;i<(nar+1)/2;i++){
// exchange values of ar[i] and ar[nar-i-1]
}
}
Assuming the array contains integers ("numbrs"), it would look something like this:
int ar[6];
.... read in values to ar[0] - ar[5].
...
exchange(ar,6);
...
void exchange{int ar[], int nar){
int tmp,i;
for(i=0;i<(nar+1)/2;i++){
// exchange values of ar[i] and ar[nar-i-1]
}
}
There are no AI answers yet. The ability to request AI answers is coming soon!
Submit Your Answer
We prioritize human answers over AI answers.
If you are human, and you can answer this question, please submit your answer.