#include<iostream> using namespace std; #include<string> #include<ctime> int main() { //数组元素的逆置 int arr[5] = { 1,5,3,2,4 }; int start = 0; int end = sizeof(arr) / sizeof(arr[0]) - 1; cout << "逆置前的数组为:" << endl; for (int i = 0; i <= end; i++) { cout << arr[i] << " "; } cout << endl; for (; start < end; start++, end--) { int temp = arr[start]; arr[start] = arr[end]; arr[end] = temp; } for (int i = 0; i < 5; i++) { cout << arr[i] << " " ; } cout << endl; //for (int i = 0; i < 5; i++) //{ // cout << arr[i] << " " ; //} //cout << endl; //int temp=0; //for (int i = 0; i < (5 - 1) / 2; i++) //{ // temp = arr[i]; // arr[i] = arr[4 - i]; // arr[4 - i] = temp; //} //for (int i = 0; i < 5; i++) //{ // cout << arr[i] << " "; //} //cout << endl; system("pause"); return 0; }