-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathptrToArray_30.cpp
49 lines (49 loc) · 1.23 KB
/
ptrToArray_30.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 <iostream>
int input(int **, int, int, int);
void display(int **, int, int, int);
using namespace std;
int main()
{
int p, m, n;
cout << "Enter number of pages: " << endl;
cin >> p;
cout << "Enter number of rows: " << endl;
cin >> m;
cout << "Enter number of columns: " << endl;
cin >> n;
int a[p][m][n];
int *ptr = (int *)a;
cout << "Enter array elements: " << endl;
input(&ptr, p, m, n);
cout << "Array elements are: " << endl;
display(&ptr, p, m, n);
return 0;
}
int input(int **q, int pg, int row, int col)
{
for (int i = 0; i < pg; i++)
{
for (int j = 0; j < row; j++)
{
for (int k = 0; k < col; k++)
{
cout << " a[" << i << "][" << j << "][" << k << "]: ";
cin >> *(*q + i * row * col + j * col + k);
}
}
}
return *q[pg * row * col];
}
void display(int **q, int pg, int row, int col)
{
for (int i = 0; i < pg; i++)
{
for (int j = 0; j < row; j++)
{
for (int k = 0; k < col; k++)
{
cout << *(*q + i * row * col + j * col + k) << " ";
}
}
}
}