-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdyn-array.cpp
More file actions
43 lines (31 loc) · 811 Bytes
/
dyn-array.cpp
File metadata and controls
43 lines (31 loc) · 811 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
//
// This program shows an example to create multidimensional arrays in C++
//
// Especificaly in this example, you can see a 2D array.
//
#include <iostream>
int main() {
// Defining dimensions
int N = 3;
int M = 3;
// Creating the matrix
double** mtrx = new double*[N];
for (int i = 0; i < N; ++i)
mtrx[i] = new double[M];
// Fill the matrix
for (int i = 0; i < N; ++i)
for (int j = 0; j < M; ++j)
mtrx[i][j] = (double)(i) + ((double)(j)/100);
// Display the result
std::cout << '\n' << "---------------------------" << '\n';
for (int i = 0; i < N; ++i) {
for (int j = 0; j < M; ++j)
std::cout << mtrx[i][j] << '\t';
std::cout << '\n';
}
// Free memory
for (int i = 0; i < N; ++i)
delete [] mtrx[i];
delete [] mtrx;
return 0;
}