题解 | #数组元素反转#
数组元素反转
https://www.nowcoder.com/practice/8c9793ae96974a9ebb153d90ef31d357
#include <iostream> using namespace std; int main() { int arr[6] = { 0 }; int len = sizeof(arr) / sizeof(int); for (int i = 0; i < len; i++) { cin >> arr[i]; } cout << "["; for (int i = 0; i < len; i++) { if (i == len - 1) { cout << arr[i] << "]" << endl; break; } cout << arr[i] << ", "; } // 输出反转后数组中元素 for (int i = 0, j = len - 1; i < j; i++, j--) swap (arr[i], arr[j]); cout << "["; for (int i = 0; i < len; i++) { if (i == len - 1) { cout << arr[i] << "]" << endl; break; } cout << arr[i] << ", "; } return 0; }#零基础学习C++##我的2023新年愿望##你的秋招进展怎么样了#
C++每日一练 文章被收录于专栏
C++刷题