#include <iostream> using namespace std; int main() { //实现数组元素逆置 //1.创建数组 int arr[] = { 1,2,3,4,5,6 }; cout << "逆置前数组" << endl; for (size_t i = 0; i < sizeof(arr) / sizeof(arr[0]); i++) { cout << arr[i] << endl; } //2.实现逆置 //记录起始下标位置 int start = 0; //记录介绍下标位置 int end = (sizeof(arr) / sizeof(arr[0])) - 1; while (start < end) { //实现元素互换 int temp = arr[start]; arr[start] = arr[end]; arr[end] = temp; //下标更新 start++; end--; } //3.打印逆置后的数组 cout << "逆置后数组" << endl; for (size_t i = 0; i < sizeof(arr) / sizeof(arr[0]); i++) { cout << arr[i] << endl; } system("pause"); return 0; }