-
Notifications
You must be signed in to change notification settings - Fork 0
/
2D_Array.cpp
49 lines (41 loc) · 974 Bytes
/
2D_Array.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
45
46
47
48
49
#include <bits/stdc++.h>
using namespace std;
int main()
{
cout << "Enter the Rows and Columns --\n";
int rows, cols;
cin >> rows >> cols;
int **head = new int *[rows];
for (int i = 0; i < rows; i++)
{
head[i] = new int[cols];
}
for (int i = 0; i < rows; i++)
{
for (int j = 0; j < cols; j++)
{
cout << "Enter the element at array[" << i << "]"
<< "[" << j << "]";
cin >> head[i][j];
cout << endl;
}
}
cout << "The allocated 2D Array is " << endl;
for (int i = 0; i < rows; i++)
{
for (int j = 0; j < cols; j++)
{
cout << "The element at array[" << i << "]"
<< "[" << j << "] is ";
cout<< head[i][j];
cout << endl;
}
}
for (int i = 0; i < rows; i++)
{
delete[] head[i];
}
delete[]head;
head=NULL;
return 0;
}