题解 | #数组元素反转#

数组元素反转

http://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] << ", ";
    }

    // write your code here......
    

    cout << "[";
    for (int i = len; i > 0; i--) {
        if (i == 1) {
            cout << arr[i-1] << "]" << endl;
            break;
        }
        cout << arr[i-1] << ", ";
    }

    return 0;
}
全部评论

相关推荐

点赞 评论 收藏
分享
评论
点赞
收藏
分享
牛客网
牛客企业服务