其實我打算用戶打印2d數組。然後按行添加數字。 我不知道如何打印行索引號。代碼是:二維陣列錯誤:行索引打印
int arr[3][3];
int sum = 0;
for (int i = 0; i < 3; i++)
{
for (int j = 0; j < 3; j++)
cin >> arr[i][j];
}
cout << endl;
for (int i = 0; i < 3; i++)
{
for (int j= 0; j < 3; j++)
cout<< arr[i][j]<<" ";
cout << endl;
}
for (int x = 0; x < 3; x++)
{
for (int y = 0; y < 3; y++)
sum += arr[x][y];
cout << "Row: " << arr[x] << "addition is:" << sum << endl;
sum = 0;
}
在第二行最後一行arr [x]打印地址。 如果我使用arr [x] [y]它告訴('y'是未定義的)。爲什麼'y'是未定義的? 和善地有人告訴我如何添加數字對角線...?