KRESH-

C++ 2D array 01

Nov 20th, 2019 (edited)
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.54 KB | None | 0 0
  1. #include <cstdlib>
  2.  
  3. using namespace std;
  4. int main()
  5. {
  6. int n, m;
  7.  
  8. cout << "rows: " << endl;
  9. cin >> n;
  10. cout << "columns: " << endl;
  11. cin >> m;
  12.  
  13. int** arr = new int*[n]; // ARRAY
  14. for (int i = 0; i < n; ++i)
  15. arr[i] = new int[m];
  16.  
  17. for (int i = 0; i < n; i++) // ARRAY INPUT
  18. {
  19. for (int j = 0; j < m; j++)
  20. {
  21. arr[i][j] = rand() % 135 + (-12);
  22. }
  23. }
  24.  
  25. for (int i = 0; i < n; i++) // ARRAY OUTPUT
  26. {
  27. for (int j = 0; j < n; j++)
  28. {
  29. cout << arr[i][j] << endl;
  30. }
  31. }
  32.  
  33. delete[] arr; // FREEING MEMORY
  34.  
  35. }
Add Comment
Please, Sign In to add comment