fork download
  1. #include <iostream>
  2. #include <vector>
  3.  
  4. using namespace std;
  5.  
  6.  
  7. vector<vector<double>> read_matrix();
  8. void print_matrix(vector<vector<double>> const& Mat);
  9.  
  10. int main() {
  11. vector<vector<double>> Mat1;
  12. vector<vector<double>> Mat2;
  13.  
  14.  
  15. Mat1 = read_matrix();
  16. print_matrix(Mat1);
  17.  
  18. /* Mat2 = read_matrix();
  19. print_matrix(Mat2);*/
  20.  
  21. return 0;
  22. }
  23.  
  24. vector<vector<double>> read_matrix() {
  25. vector<vector<double>> TempMat;
  26. size_t row(0), col(0);
  27.  
  28. cout << "Matrix input :" << endl;
  29. cout << " Rows count : ";
  30. cin >> row;
  31. cout << " Columns count : ";
  32. cin >> col;
  33.  
  34.  
  35. double temp(0.0);
  36. for (size_t i = 0; i < row; ++i) {
  37. TempMat.push_back(vector<double>()); // NOT sure about this !!
  38.  
  39. for (size_t j = 0; j < col; ++j) {
  40. cout << " [" << i+1 << "," << j+1 << "]=";
  41. cin >> temp;
  42. TempMat[i].push_back(temp);
  43. }
  44. }
  45.  
  46.  
  47. return TempMat;
  48. }
  49.  
  50. void print_matrix(vector<vector<double>> const& Mat) {
  51. for (auto row : Mat) {
  52. for (auto cell : row)
  53. cout << cell << " ";
  54.  
  55. cout << endl;
  56. }
  57. }
  58.  
Success #stdin #stdout 0s 3280KB
stdin
1 2 1 2 3 4
stdout
Matrix input :
  Rows count :   Columns count :   [1,1]=  [1,2]=1 2