Answer to Question #24199 in C++ for Nourh

Question #24199
Suppose I have an array of ints called numbers that has 5 values in it. Write code that reverses the order of the values in the array, such that the value that was last will now appear first, and vice-versa.
1
Expert's answer
2013-02-14T07:39:03-0500
# include <iostream>

using namespace std;

void reverse(int ar[5]){
int loc;
loc=ar[0];
ar[0]=ar[4];
ar[4]=loc;

loc=ar[1];
ar[1]=ar[3];
ar[3]=loc;
}
void print(int ar[]){for(int i=0;i<5;i++) cout<<"ar["<<i<<"]="<<ar[i]<<"& ";cout<<endl;}
int main(){
int ar[5]={1,2,3,4,5};
print(ar);
reverse(ar);
print(ar);

system("PAUSE");
return 0;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
APPROVED BY CLIENTS