Загрузка...

How to equate one multidimensional array to another?

Thread in C/C++ created by Тетраэдр228 Aug 4, 2019. 166 views

  1. Тетраэдр228
    Тетраэдр228 Topic starter Aug 4, 2019 0 Jul 2, 2019
    Что я делаю не так?
    Code

    #include<iostream>

    using namespace std;

    const int A = 3;
    const int B = 4;
    int Arr[A][B];
    int Arr2[A][B];

    int main()
    {
    for (int i = 0; i <= A; i++) {
    for (int j = 0; j <= B; j++) {
    Arr[i][j] = rand() % 89 + 10;
    cout << Arr[i][j]<<" ";
    Arr2[i][j] = Arr[i][j];
    }
    cout << endl;
    }
    cout << endl;

    for (int i = 0; i <= A; i++) {
    for (int j = 0; j <= B; j++) {
    cout << Arr2[i][j] << " ";
    }
    cout << endl;
    }

    system("pause");
    }

    Вывод:
    [IMG]
     
  2. de9x
    de9x Aug 5, 2019 Frontend developer 141 Jan 3, 2019
    почему <=? за границы массива уходишь. поменяй на < и будет у тебя чеколатная жызнь
     
  3. ZLOYSERGUNYA
    ZLOYSERGUNYA Aug 5, 2019 save what remains 787 Jan 4, 2017
    Старайся не использовать глобальные переменные и пользуйся динамической памятью
    Code

    using namespace std;

    int main() {
    const int A = 3;
    const int B = 4;
    int Arr[A][B];
    int Arr2[A][B];

    for (int i = 0; i < A; i++) {
    for (int j = 0; j < B; j++) {
    Arr[i][j] = rand() % 89 + 10;
    cout << Arr[i][j] << " ";
    Arr2[i][j] = Arr[i][j];
    }
    cout << endl;
    }
    cout << endl;

    for (int i = 0; i < A; i++) {
    for (int j = 0; j < B; j++) {
    cout << Arr2[i][j] << " ";
    }
    cout << endl;
    }

    system("pause");
    }
     
  4. adziri
    adziri Aug 6, 2019 mental handicap 8 Dec 20, 2017
    Code
    if (std::memcmp(Arr, Arr2, sizeof(Arr2)) == 0) {
    std::cout << "Arr1 == Arr2\n";
    }
     
Loading...
Top