diff --git a/2D array.cpp b/2D array.cpp new file mode 100644 index 0000000..8abfdb4 --- /dev/null +++ b/2D array.cpp @@ -0,0 +1,29 @@ +// CPP program +#include +#include +using namespace std; +int main() +{ + int n = 3; + int m = 4; + + /* + We create a 2D vector containing "n" + elements each having the value "vector (m, 0)". + "vector (m, 0)" means a vector having "m" + elements each of value "0". + Here these elements are vectors. + */ + vector> vec( n , vector (m, 0)); + + for(int i = 0; i < n; i++) + { + for(int j = 0; j < m; j++) + { + cout << vec[i][j] << " "; + } + cout<< endl; + } + + return 0; +}