peshopbs2

Input/output two-dimensional array

Aug 18th, 2016
132
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.49 KB | None | 0 0
  1. #include <iostream>
  2. #define MAXN 10
  3. using namespace std;
  4.  
  5. void input_2d(int &n, int &m, int a[][MAXN]) {
  6.     cin >> n >> m;
  7.     for (int i = 0; i < n; i++) {
  8.         for (int j = 0; j < m; j++) {
  9.             cin >> a[i][j];
  10.         }
  11.     }
  12. }
  13.  
  14. void output_2d(int &n, int &m, int a[][MAXN]) {
  15.    
  16.     for (int i = 0; i < n; i++) {
  17.         for (int j = 0; j < m; j++) {
  18.             cout << a[i][j] << " ";
  19.         }
  20.         cout << endl;
  21.     }
  22. }
  23.  
  24. int main() {
  25.  
  26.     int a[MAXN][MAXN], n, m;
  27.     input_2d(n, m, a);
  28.     output_2d(n, m, a);
  29.     return 0;
  30. }
Advertisement
Add Comment
Please, Sign In to add comment