-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathdynamic3d.c
57 lines (55 loc) · 1.25 KB
/
dynamic3d.c
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
50
51
52
53
54
55
56
57
/*
* DYNAMIC 3D ARRAYS IN HEAP
*/
#include <stdio.h>
#include <stdlib.h>
int main()
{
int height;
int rows;
int cols;
printf("Enter the height,rows and cols of the array\n");
scanf("%d %d %d",&height,&rows,&cols);
int ***arr = (int***)malloc(sizeof(int **)*height);
for(register int i=0;i<height;i++)
{
arr[i]=(int **)malloc(sizeof(int *)*rows);
for(register int j=0;j<rows;j++)
{
arr[i][j]=(int *)malloc(sizeof(int)*cols);
}
}
printf("Enter the elements of the array\n");
for(register int i=0;i<height;i++)
{
for(register int j=0;j<rows;j++)
{
for(register int k=0;k<cols;k++)
{
scanf("%d",&arr[i][j][k]);
}
}
}
printf("Entered array\n");
for(register int i=0;i<height;i++)
{
for(register int j=0;j<rows;j++)
{
for(register int k=0;k<cols;k++)
{
printf("%d",arr[i][j][k]);
}
printf("\n");
}
printf("------\n");
}
for(register int i=0;i<height;i++)
{
free(arr[i]);
for(register int j=0;j<rows;j++)
{
free(arr[i]);
}
}
free(arr);
}