题解 | #数组元素反转#
数组元素反转
http://www.nowcoder.com/practice/8c9793ae96974a9ebb153d90ef31d357
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] << ", ";
}
int shu[6]={0};
for(int i=len-1;i>=0;i--){
shu[len-i-1]=arr[i];
}
// write your code here......
cout << "[";
for (int i = 0; i < len; i++) {
if (i == len - 1) {
cout << shu[i] << "]" << endl;
break;
}
cout << shu[i] << ", ";
}
return 0;
}