【问题标题】:Access array member through two subscripts [duplicate]通过两个下标访问数组成员[重复]
【发布时间】:2019-11-16 08:50:34
【问题描述】:

我已将矩阵的成员存储到一维数组中。现在的问题是我需要通过这样的 2 索引符号来访问这些成员:

int matrix[2][3] = {{ 1 , 2 , 3 },{ 4, 5 , 6 }}; // this is no longer available
    int x , y;
    //Stored matrix data on array[]
    int array[] = {1,2,3,4,5,6}; // only this member available

    cout << "Insert the x index : ";
    cin>> x;
    cout << "Insert the y index : ";
    cin>> y;

那么,我如何打印存储在中的矩阵 [1][1] 成员 在数组[]上??

【问题讨论】:

    标签: c++


    【解决方案1】:

    像这样自己计算索引:

    array[row * columnSize + column]
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-08-02
      • 1970-01-01
      相关资源
      最近更新 更多