Skip to content

Commit dd20bf9

Browse files
committed
fixed dynamic array
1 parent 899be6a commit dd20bf9

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

others/sparse_matrix.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,9 @@ int main() {
1313
std::cin >> m;
1414
std::cin >> n;
1515

16-
int a[m][n];
16+
int **a = new int *[m];
17+
for (int i = 0; i < m; i++) a[i] = new int[n];
18+
1719
std::cout << "Enter matrix elements:";
1820
std::cout << "\n";
1921

@@ -37,4 +39,8 @@ int main() {
3739
std::cout << "Sparse matrix";
3840
else
3941
std::cout << "Not a sparse matrix";
42+
43+
for (int i = 0; i < m; i++) delete[] a[i];
44+
delete[] a;
45+
return 0;
4046
}

0 commit comments

Comments
 (0)