fork download
  1. #include <iostream>
  2. #include <vector>
  3. using namespace std;
  4. typedef vector<vector<double>> Matrix;
  5. typedef vector<double>::size_type mat_size;
  6.  
  7.  
  8. void printMat(Matrix &mat){
  9. for (auto &a: mat){
  10. for (auto &val: a){
  11. cout << " "<< val << " ";
  12. }
  13. cout << endl;
  14. }
  15. }
  16.  
  17. void changeMat(Matrix &mat, mat_size i, mat_size j, double val){
  18. if(i<mat.size() && j<mat[i].size()){
  19. mat[i][j] = val;
  20. }
  21. }
  22. void border(){
  23. cout << "-------------------\n";
  24. }
  25. int main() {
  26. Matrix mat {{1,2,3}, {4,5,6}, {7,8,9}};
  27. printMat(mat);
  28. border();
  29. changeMat(mat, 1,1, 0);
  30. printMat(mat);
  31. border();
  32. changeMat(mat, 1,2, 0);
  33. printMat(mat);
  34. border();
  35. changeMat(mat, 4,1, 0);
  36. changeMat(mat, 2,5, 0);
  37. printMat(mat);
  38. // your code goes here
  39. return 0;
  40. }
Success #stdin #stdout 0s 3432KB
stdin
Standard input is empty
stdout
 1  2  3 
 4  5  6 
 7  8  9 
-------------------
 1  2  3 
 4  0  6 
 7  8  9 
-------------------
 1  2  3 
 4  0  0 
 7  8  9 
-------------------
 1  2  3 
 4  0  0 
 7  8  9