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);
Comments
Leave a comment