#include<iostream>
using namespace std;
int main()
{
int arr[] = { 1,2,3,4,5 };
int temp = 0;
int start = 0;
int end = sizeof(arr) / sizeof(arr[0]) - 1;//得到数组最后一个元素的下标
int a = end;
for (int i = 0; i <= end; i++)
{
cout << arr[i] << endl;
}
while (start < end)
{
temp = arr[start];
arr[start] = arr[end];
arr[end] = temp;
start++;
end--;
}
cout << endl;
for (int j = 0; j <= a; j++)
{
cout << arr[j] << endl;
}
system("pause");
return 0;
}
数组元素逆置
最新推荐文章于 2023-09-25 17:08:47 发布