fork download
  1. #include <iostream>
  2. #include <cmath>
  3.  
  4. using namespace std;
  5.  
  6. void print(int ** m, unsigned rows, unsigned cols)
  7. {
  8. for (int i = 0; i < rows; i++)
  9. {
  10. for (int j = 0; j < cols; j++)
  11. {
  12. cout << m[i][j] << " ";
  13. }
  14. cout << endl;
  15. }
  16. }
  17.  
  18.  
  19. int main()
  20. {
  21. int ** m = new int *[5];
  22. for (int i = 0; i < 5; i++)
  23. {
  24. m[i] = new int[5];
  25. for (int j = 0; j < 5; j++)
  26. {
  27. m[i][j] = i + j;
  28. cout << m[i][j] << " ";
  29. }
  30. cout << endl;
  31. }
  32. cout << "==========================" << endl;
  33.  
  34. print(m, 5, 5);
  35. return 0;
  36. }
Success #stdin #stdout 0s 15240KB
stdin
Standard input is empty
stdout
0 1 2 3 4 
1 2 3 4 5 
2 3 4 5 6 
3 4 5 6 7 
4 5 6 7 8 
==========================
0 1 2 3 4 
1 2 3 4 5 
2 3 4 5 6 
3 4 5 6 7 
4 5 6 7 8