Warm tip: This article is reproduced from serverfault.com, please click

Cant print an 2d array in function c++

发布于 2020-11-29 11:10:25

I have a problem with printing isSymmetric function, I don't know how to print it correctly. And I couldn't find a solution for this in google.

#include <iostream>
#include <iomanip>

using namespace std;

const int MAX = 100;

void transpose(int mat[MAX][MAX], int tr[][MAX], int N)
{
    for (int i = 0; i < N; i++)
        for (int j = 0; j < N; j++)
            tr[i][j] = mat[j][i];
}

bool isSymmetric(int mat[MAX][MAX], int N)
{
    int tr[MAX][MAX];
    transpose(mat, tr, N);
    for (int i = 0; i < N; i++)
        for (int j = 0; j < N; j++)
            if (mat[i][j] != tr[i][j])
                return false;
    return true;
}

void main() {
    int matrix_size;
    cout << "Enter rows and columns for quaratic matrix: ";
    cin >> matrix_size;
    //int* a = (int*)malloc(row * col * sizeof(int));
    const int col = 99, row = 99;
    int a[col][row];
    srand((unsigned)time(NULL));
    for (int i = 0; i < matrix_size; i++)
        for (int j = 0; j < matrix_size; j++)
            a[i][j] = 0 + rand() % (20 - 0 + 1);
    cout << endl;
    for (int i = 0; i < matrix_size; i++) {
        for (int j = 0; j < matrix_size; j++)
            cout << setw(4) << a[i][j];
        cout << endl;
    }
    //if (isSymmetric(a, matrix_size)) has a problem
    if (isSymmetric(a, matrix_size))
        cout << "Yes";
    else
        cout << "No";
}

I get the following error and I have no clue what its sayings Error (active) E0167 argument of type "int ()[99U]" is incompatible with parameter of type "int ()[100]"

Questioner
Roman Roman
Viewed
0
Tomer 2020-11-29 19:18:54

Your functions require int mat[MAX][MAX] in their arguments, where MAX is 100. You pass them int a[col][row] where row and col are 99. This creates this problem, as an array with 100 elements is not the same as array with 99 elements...