Matrix Addition and Subtraction with Functions
MediumRead the rows and columns of a matrix A followed by its elements row by row, then the rows and columns of a matrix B followed by its elements, and print A, B, A + B, and A - B, each under its own heading line: matrix A:, matrix B:, A + B:, and A - B:, with every matrix printed one row per line and elements separated by single spaces. Read each matrix with a user-defined function readMatrix that returns 1 on success and 0 when a read fails, and print each with a user-defined function printMatrix; both take the matrix as int m[MAX][MAX] plus the real row and column counts. Each dimension must be between 1 and 10 (MAX); otherwise print dimensions must be between 1 and 10 and return 1. As soon as B's dimensions are read, if they differ from A's, print matrices are not compatible for addition and subtraction and return 1 without reading B's elements. If any number cannot be read, print invalid input and return 1.
Success Criteria
Your code must pass 8 test case(s) to complete this exercise. 3 hint(s) are available if you need help.
How did you find this exercise?
Your rating helps us improve the content.
Sign in to track your progress
You can work on exercises as a guest, but sign in to track your progress and save your submissions.