Answer to Question #256264 in C++ for RAHUL

Question #256264

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}"


1
Expert's answer
2021-10-26T15:09:40-0400
#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;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS