C Program to implement a basic 3D Array..

#include<stdio.h>

void main()
{
    int a[50][50][50];
    int x,y,z,i,j,k;
    printf("Enter the no of rows,columns and planes..");
    scanf("%d%d%d",&x,&y,&z);
    printf("Enter the elements one by one..\n");

    // Reading a 3D array...

    for(k=0;k<z;k++)
    {
        printf("Plane %d:\n",k+1);
        for(i=0;i<x;i++)
        {
            for(j=0;j<y;j++)
            {
                scanf("%d",&a[k][i][j]);
            }
        }
        printf("\n");
    }

    // Displaying a 3D array...

    printf("\nThe Entered 3D Array is as follows..\n");
     for(k=0;k<z;k++)
    {
        printf("Plane %d:\n",k+1);
        for(i=0;i<x;i++)
        {
            for(j=0;j<y;j++)
            {
               printf("%d ",a[k][i][j]);
            }
            printf("\n");
        }
        printf("\n");
    }
}

No comments:

Post a comment