1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62
| #include <iostream>
using namespace std;
int main() {
int arr1[10];
int arr2[3] = { 1,2 }; cout << arr2[0] << endl;
int arr3[] = { 1,2,3,4 };
int 数组长度 = sizeof(arr3) / sizeof(int); for (int i = 0;i < 数组长度;i++) { cout << arr3[i] << endl; } cout << "----------" << endl; for (int i : arr3) { cout << i << endl; } cout << "----------" << endl; for (int& i : arr3) { if (i == 1) { i = 8; } } cout << arr3[0] << endl; cout << "----------" << endl;
int arr4[] = {111, 122, 123, 65, 12, 54, 8, 3, 26, 1, 99}; int* arr5 = arr4; 数组长度 = sizeof(arr4) / sizeof(int); for (int i = 0;i < 数组长度 - 1;i++) { for (int j = 0;j < 数组长度 - 1 - i;j++) { if (arr5[j] > arr5[j + 1]) { int num = arr5[j]; arr5[j] = arr5[j + 1]; arr5[j + 1] = num; } } } for (int i = 0;i < 数组长度;i++) { cout << arr4[i] << endl; }
return 0; }
|