Two Dimension Array
// Ex_2DArray.cpp
#include <stdio.h> #include <stdlib.h> #include <iostream> using namespace std; int main() { int x, y; scanf("%d,%d",&x,&y); // row:x , column: y int** arr; arr = new int*[x]; for (int j = 0; j < x; j++ ) arr[j] = new int[y]; for (int i = 0; i< x; i++) for (int j = 0; j <y; j++) arr[i][j] = i-j; for (int i = 0; i< x; i++) { for (int j = 0; j <y; j++) { cout << arr[i][j]<<'\t'; } cout<<endl; } for (int j = 0; j < x; j++ ) delete arr[j]; delete [] arr; cout <<endl; return 0; }
$ ./Ex_2DArray
4, 5
0 -1 -2 -3 -4
1 0 -1 -2 -3
2 1 0 -1 -2
3 2 1 0 -1