(一)
a[0] | a[1] | a[2] | a[3] | a[4] |
---|---|---|---|---|
a[0][1] | a[1][1] | a[2][1] | a[3][1] | a[4][1] |
a[0][2] | a[1][2] | a[2][2] | a[3][2] | a[4][2] |
a[0][3] | a[1][3] | a[2][3] | a[3][3] | a[4][3] |
a[0][4] | a[1][4] | a[2][4] | a[3][4] | a[4][4] |
a[行][列]
例:存
1 | 2 | 3 |
---|---|---|
4 | 5 | 6 |
7 | 8 | 9 |
#include<iostream>
#include<cstdio>
using namespace std;
int main(){
int a[3][3];
for(int i = 0;i<=2;i++){
for(int j = 0;j<=2;j++){
cin >> a[i][j];
}
}
for(int i = 0;i<=2;i++){
for(int j = 0;j<=2;j++){
cout << a[i][j] << " ";
}
cout << endl;
}
return 0;
}
#include<iostream>
#include<cstdio>
using namespace std;
int main(){
int a[105][105] , n , m , num , a1 = 1;
cin >> n >> m;
num = n * m;
for(int i = 1;i <= n;i++){
for(int j = 1;j <= m;j++){
a[i][j] = a1;
a1 = a1 + 1;
}
}
for(int i = n;i >= 1;i--){
for(int j = m;j >= 1;j--){
cout << a[i][j] << " ";
}
cout << endl;
}
return 0;
}
(二)
初始化:
(1)
int a[3][3] = {{1,2,3},{4,5,6},{7,8,9}};
(2)
for(int i = 0;i <= 2;i++){
for(int j = 0;j <= 2;j++){
cin >> a[i][j];
}
}
输出:
(1)
cout << a[1][0];//4
(2)
for(int i = 0;i <= 2;i++){
for(int j = 0;j <= 2;j++){
cout << a[i][j];
}
}
标签:std,main,cout,int,namespace,二维,数组,include
From: https://www.cnblogs.com/hnzzlxs01/p/16655873.html