-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy path2darray.cpp
44 lines (41 loc) · 796 Bytes
/
2darray.cpp
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
44
/*
* 2 D ARRAYS IN HEAPS
*/
#include <iostream>
using namespace std;
int main()
{
int rows;
int cols;
cout << "Enter the rows and cols of the 2d array" << endl;
cin >> rows;
cin >> cols;
int **arr;
arr = new int*[rows]; // declared array
for(int i=0;i<rows;i++)
{
arr[i] = new int[cols];
}
cout << "Enter the values of 2d array" << endl;
for(int i=0;i<rows;i++)
{
for(int j=0;j<cols;j++)
{
cin >> arr[i][j];
}
}
cout << "Entered 2d array" << endl;
for(int i=0;i<rows;i++)
{
for(int j=0;j<cols;j++)
{
cout << arr[i][j] << " ";
}
cout << endl;
}
for(int i=0;i<rows;i++)
{
delete [] arr[i];
}
delete [] arr;
}