#C++ Day12 October 22 2025

//7 – 1 One – dimensional Array

#include <iostream>

using namespace std;

int main() {

//1.the definition of array

//数据类型 数组名[数字 / 常量表达式];

int a[1024] = {1,2,3,45};

double b[520];

char c[1314];

//double a[1024];  //this is an error, we should not define two times the same name’s array

//All the elements have the same date type in an array 

//the array’s lower number(下标) is start from 0 (a[0] a[1] a[2])

/*

int n = 1000;

int d[n];//error

//there must be a constant value in the array’s lower symbol 

*/

int x1[10], x2[20], x3, x4, x5,x6[100]; // the array can be listed in a single line

//2.the access to the elements

//数组名 [下标]

//array’s name [index]

a[0], a[1023];

for (int i = 0; i < 4; ++i)

{

cout << a[i] << endl;

//only access the initialized values

}

//3.Reverse output

//please type in the n(n<100), and n numerical numbers, please reverse output these n numerical numbers

//输入一个n(n<100),和n个数,请逆序输出这n个数

int n;

int x[100];

cin >> n;

for (int i = 0; i < n; ++i) {

cin >> x[i];

}

for (int i = n – 1; i >= 0; –i) {

cout << x[i] << ‘ ‘;

}

cout <<  endl;

return 0;

}

//7 – 2 Two – dimensional Array

#include <iostream>

using namespace std;

//one dimensional array is a sequential list

//two dimensional array is like an excel table, which has  rows and columns

int main() {

//two dimensional array can be related to matrices in  linear algebra

//1.the definition of two dimensional arrays

//data type    array name    [rows] [columns] ;

//数据类型 数组名 [行] [列]

int arr[3][4];

for (int i = 0; i < 3; ++i) {

for (int j = 0; j < 3; ++j) {

arr[i][j] = i * j;

}

}

int b[4][4]{

{1,2},

{2,3},

{6,7,8},

{9,1}

};

for (int i = 0; i < 4; ++i) {

for (int j = 0; j < 4; ++j) {

cout << b[i][j] << ‘ ‘;

}

cout << endl;

}

cout << b << ‘ ‘; //the array name represents the starting address

return 0;

}