- Notifications
You must be signed in to change notification settings - Fork 366
/
Copy pathjagged-array.cpp
48 lines (38 loc) · 862 Bytes
/
jagged-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
#include<bits/stdc++.h>
usingnamespacestd;
#definelllonglong
#definepb push_back
#definemod1000000007
#defineendl'\n'
intmain(){
int n;
cin>>n;
// creation of 2array
//
int *p= newint [n];
int **arr= newint *[n];
for (int i = 0; i < n; i++) {
cout<<"enter the no of cols in row "<<i<<":";
cin>>p[i];
arr[i]= newint[p[i]];
}
// taking input
for (int i = 0; i < n; i++) {
for (int j = 0; j <p[i] ; j++) {
cin>>arr[i][j];
}
}
// giving the outputl
for (int i = 0; i < n; i++) {
for (int j = 0; j < p[i]; j++) {
cout<<arr[i][j]<<"";
}
cout<<endl;
}
//releasing of all the heap memory
for (int i = 0; i < n; i++) {
delete [] arr[i];
}
delete []arr;
return0;
}