1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
|
include <iostream>
#include <iomanip>
constexpr size_t ROWS {4};
constexpr size_t COLS {4};
void displayMatrix(const int matrix[ROWS][COLS]);
bool isEqual(const int matrixA[ROWS][COLS], const int matrixB[ROWS][COLS]);
int main() {
const int matrixA[ROWS][COLS] { { 1, 0, 19, -3 }, { 0, 2, -147, 5 }, { 19, -147, 3, 42 }, { -3, 5, 42, 4 } };
const int matrixB[ROWS][COLS] { {42, 17, -1, 3}, {92, 77, 0, -2}, {4, 4, -2, 3}, {1, 23, 19, 47} };
std::cout << "matrixA:\n";
displayMatrix(matrixA);
std::cout << "matrixB:\n";
displayMatrix(matrixB);
std::cout << "\nMatrix a is Equal to Matrix b: " << std::boolalpha << isEqual(matrixA, matrixB) << '\n';
}
bool isEqual(const int matrixA[ROWS][COLS], const int matrixB[ROWS][COLS]) {
for (size_t rows = 0; rows < ROWS; ++rows)
for (size_t columns = 0; columns < COLS; ++columns)
if (matrixA[rows][columns] != matrixB[rows][columns])
return false;
return true;
}
void displayMatrix(const int matrix[ROWS][COLS]) {
for (size_t row = 0; row < ROWS; ++row) {
for (size_t col = 0; col < COLS; ++col)
std::cout << std::setw(8) << matrix[row][col];
std::cout << '\n';
}
}
| |