Thursday, 13 May 2021

Multi dimensional arrays in C programming

Multi dimensional arrays can store values in more than two dimensions it can also be defined as an array of two dimensional array.

If an array contains 'n' dimensions, a particular element is specified by using 'n' subscripts. A multidimensional array can contain as many indices as needed and the required of memory increases with the number of indices used.


 Example: Write a C program to read values into multidimensional array and print them of order 2x2x2

#include<stdio.h>
void main()
{
 int a[2][2][2],i,j,k;
 printf(" enter values into array");
 for(i=0;i<2;i++)
 {
 for(j=0;j<2;j++)
 {
 for(k=0;k<2;k++)
 {
   scanf("%d",&[i][j][k]);
 }
}
}

printf(" array values are")
 for(i=0;i<2;i++)
 {
 for(j=0;j<2;j++)
 {
 for(k=0;k<2;k++)
 {
   printf("%d",a[i][j][k]);
 }
}
}
getch();
}

0 comments:

Post a Comment

Note: only a member of this blog may post a comment.

Find Us On Facebook

Computer Basics

More

C Programming

More

Java Tutorial

More

Data Structures

More

MS Office

More

Database Management

More
Top