// prob2.cpp // example problem for exam #1 // CS210 S'03 Ray S. Babcock 2/20/03 // #include using namespace std; void swap(int *, int *); int main (void) { int ary[]={0, 2, 4, 6, 1, 3, 5, 7}; int last(0); for( int i = 0; i<8; i++) { last = 7 - i; swap(&(ary[i]), &(ary[last])); // if(i== 3) // { // for( int i=0; i<8; i++) // cout << ary[i] << " "; // cout << endl; // } } // print array for( int i=0; i<8; i++) cout << ary[i] << " "; cout << endl; } void swap(int * a_ptr, int * b_ptr) { int tmp; tmp = *a_ptr; *a_ptr = *b_ptr; *b_ptr = tmp; }