-
Notifications
You must be signed in to change notification settings - Fork 0
/
3D_array.c
56 lines (51 loc) · 1.31 KB
/
3D_array.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
#include <stdio.h>
#include <stdlib.h>
int main()
{
int l,b,h,i,j,k,a[10][10][10];
printf("Enter the length of the 3D array : ");
scanf("%d",&l);
printf("Enter the breadth of the 3D array : ");
scanf("%d",&b);
printf("Enter the height/no.of layers in the 3D array : ");
scanf("%d",&h);
printf("\nYour array has %d rows,%d columns and %d layers.\n",l,b,h);
printf("Thus there are %d elements in this 3D array.\n",l*b*h);
printf("Populate the array : ");
for(k=0;k<h;k++)
{
for(i=0;i<l;i++)
{
for(j=0;j<b;j++)
{
scanf("%d",&a[i][j][k]);
}
}
}
printf("\nYour 3D array looks like this : \n\n");
for(k=0;k<h;k++)
{
for(i=0;i<l;i++)
{
for(j=0;j<b;j++)
{
printf("a[%d][%d][%d] = %d\n",i,j,k,a[i][j][k]);
}
}
}
printf("\nYour 3-dimensional number block looks like this : \n\n");
for(k=0;k<h;k++)
{
printf("Layer number %d:\n",k+1);
for(i=0;i<l;i++)
{
for(j=0;j<b;j++)
{
printf("%d ",a[i][j][k]);
}
printf("\n");
}
printf("\n");
}
return 0;
}