lundi 30 décembre 2019

I need to change the main program, because I want input from the user how can I do it?

#include <iostream> 
using namespace std; 

const int MAX = 100; 
  \\ Fills transpose of mat[N][N] in tr[N][N] 
void transpose(int mat[][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]; 
} 

// Returns true if mat[N][N] is symmetric, else false 
bool isSymmetric(int mat[][MAX], int N) 
{ 
    int tr[N][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; 
} 

// Driver code 
int main() 
{ 
    int mat[][MAX] = { { 1, 3, 5 },  // I need to replace this with a cin //command
                       { 3, 2, 4 }, 
                       { 5, 4, 1 } }; 

    if (isSymmetric(mat, 3)) 
        cout << "Yes"; 
    else
        cout << "No"; 
    return 0; 
}

The code is to find out if the matrix is symmetric or not, but I'm confused how can I read the input from user and not from the code. I've did a simple solution basically I've created the transpose of given matrix and then i checked if transpose and given matrices are same or not. 1) Create transpose of given matrix. 2) Check if transpose and given matrices are same or not

Aucun commentaire:

Enregistrer un commentaire