Q:Write a program which read the following (3x3 dimensional) array and then display it.
"\\begin{Bmatrix}\n 10 & 50 & 70 \\\\\n 40 & 80 & 30 \\\\\n 20 & 55 & 60 \\\\\n\\end{Bmatrix}"
#include <iostream>
#include <array>
int main() {
using Matrix = std::array<std::array<int, 3>, 3>;
Matrix m;
// read
for (size_t row = 0; row < 3; row++) {
for (size_t col = 0; col < 3; col++) {
std::cin >> m[row][col];
}
}
// display
for (auto const& r: m) {
for (auto c: r) {
std::cout << c << ' ';
}
std::cout << '\n';
}
return 0;
}
Comments
Leave a comment