Chapter 08

2次元配列

Nanase
Nanase
2020.11.05に更新

int s[4][1] //縦が4、横が1
この場合、表一番下の行の真ん中になります。

s[0][0] s[0][1] s[0][2]
s[1][0] s[1][1] s[1][2]
s[2][0] s[2][1] s[2][2]
s[3][0] s[3][1] s[3][2]
s[4][0] s[4][1] s[4][2]

int t,y; //tは縦の添え字、yは横の添え字とした場合
int sum;

s[t][y] s[t][y] s[t][y]
s[t][y] s[t][y] s[t][y]
s[t][y] s[t][y] s[t][y]
s[t][y] s[t][y] s[t][y]
s[t][y] s[t][y] s[t][y]
for (t=0; t<5; t++){
  for (y=sum=0; y<3; y++){
    sum = sum + s[t][y];
  }
  printf("yoko sum: %d\n", sum);
}
s[t][y] s[t][y] s[t][y]
s[t][y] s[t][y] s[t][y]
s[t][y] s[t][y] s[t][y]
s[t][y] s[t][y] s[t][y]
s[t][y] s[t][y] s[t][y]
for (y=0; y<5; y++){
  for (t=sum=0; t<3; t++){
    sum = sum + s[t][y];
  }
  printf("tate sum: %d\n", sum);
}