0
int main(){
    int matrix[4][4] = {{1,2,1,4},
                        {5,6,2,8},
                        {9,10,1,12},
                        {13,14,4,16}};

    if (Equal(matrix))
    {
        cout << "True" << endl;
    }
    else
        cout << "False" << endl;
    
    system("pause");
    return 0;
}
bool Equal(int matrix[4][4]){
    int count = 0;
    for (int i = 0; i < 4; i++)
    {
        for (int j = 0; j < 4; j++)
        {
            if (matrix[i][j] == matrix[j][i])
            {
                count++;
            }   
        }
        if (count == 4)
        {
            return true;
        }
        else
            count = 0;
    }
    return false;
}

I want to make an application that returns true if any row is equal to any column.

I've tried :

int matrix[4][4] = {{1,5,9,13},
                    {5,6,7,8},
                    {9,10,11,12},
                    {13,14,15,16}};

returned true.

I've tried :

int matrix[4][4] = {{1,2,1,4},
                    {5,6,2,8},
                    {9,10,1,12},
                    {13,14,4,16}};

returned false.(it was supposed to turn right)

I will be glad if you help.

  • You have to use 3 loops. `row[i] == col[j]` need to iterate over the "line". – Jarod42 Apr 05 '22 at 15:19
  • hint: you are always comparing the first row with the first column, the second row with the second column, etc... – Federico Apr 05 '22 at 15:20
  • *but it doesn't work* -- [What is a debugger?](https://stackoverflow.com/questions/25385173/what-is-a-debugger-and-how-can-it-help-me-diagnose-problems) – PaulMcKenzie Apr 05 '22 at 15:27

0 Answers0