//1.声明一个二维数组
int arr[4][3] = {0};
int brr[3][3] = {0};
//2.第二种初始化的方式
int arr1[4][3] = {{1,2,3},{2,2,3},{3,2,3},{4,2,3}};
int brr1[3][3] = {{100,20,50},{99,81,49},{25,30,19}};
//3.取值 下标来取值
printf("arr1[0][0] = %d\n",arr1[0][0]);
printf("arr1[0][1] = %d\n",arr1[0][1]);
printf("arr1[0][2] = %d\n",arr1[0][2]);
printf("brr1[1][0] = %d\n",brr1[1][0]);
printf("brr1[1][1] = %d\n",brr1[1][1]);
printf("brr1[1][2] = %d\n",brr1[1][2]);
//4.赋值
arr[0][0] = 100;
arr[0][1] = 20;
arr[0][2] = 15;
brr[0][0] = 99;
brr[0][1] = 90;
brr[0][2] = 10;
//5.二维数组的遍历 行 列
int i = 0;//行
int j = 0;//列
for(i = 0;i < 4;i++)//行
{
for(j = 0;j < 3;j++)//列 外层循环 1次 内层循环3次
{
printf(" arr1[%d][%d] = %d ",i,j,arr1[i][j]);
}
printf("\n");
}
|
|