Preview:
#include<iostream>
using namespace std;

int main() {
    int cases;
    cout << "Enter no of Cases:";
    cin >> cases;

    for (int caseNumber = 1; caseNumber <= cases; caseNumber++) {
        cout << "Enter the size of matrix:";
        int n, count = 0;
        cin >> n;
        int arr1[n][n];
        int arr2[n][n];

        cout << "Enter Matrix A" << endl;
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < n; j++) {
                cout << "Enter element of matrix A:";
                cin >> arr1[i][j];
            }
        }

        cout << "Enter Matrix B :" << endl;
        for (int m = 0; m < n; m++) {
            for (int o = 0; o < n; o++) {
                cout << "Enter element of matrix B:";
                cin >> arr2[m][o];
            }
        }

        bool possible = true;

        for (int x = 0; x < n; x++) {
            for (int y = 0; y < n; y++) {
                if (arr1[x][y] != arr2[x][y]) {
                    arr1[x][y] = arr2[x][y];
                    count++;
                    cout<<"caught symmetrisizm  ";
                }
            }
        }

        // Check if the matrix can be converted and is not symmetric
        for(int i=0;i<n;++i){
             for(int j=0;j<n;++j){
                if(i+j!=0 && i!=j){
                    if(arr1[i][j]==arr2[j][i]){
                      cout<<"Symmetrism"<<endl;
                      count++;  
                    }
                }
             }
        }
        for (int i = 0; i < n; i++) {
            for (int j = i + 1; j < n; j++) {
                if (arr1[i][j] == arr1[j][i]) {
                    possible = false;
                    break;
                }
            }
            if (!possible) {
                break;
            }
        }

        if (possible) {
            cout << "Matrix A is Converted into B as  :" << endl;
            for (int a = 0; a < n; a++) {
                for (int b = 0; b < n; b++) {
                    cout << arr1[a][b] << " ";
                }
                cout << endl;
            }
            cout << "Case " << caseNumber << ": " << count << endl;
        } else {
            cout << "Case " << caseNumber << ": -1 (Conversion is not possible while obeying the rules.)" << endl;
        }
    }

    return 0;
}
downloadDownload PNG downloadDownload JPEG downloadDownload SVG

Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!

Click to optimize width for Twitter