Introduction
C Programming
C Advanced
Important C Programs
Modal Box
Tutorials
C is a very powerful and widely used language. It is used in many scientific programming situations. It forms (or is the basis for) the core of the modern languages Java and C++. It allows you access to the bare bones of your computer.C++ is used for operating systems, games, embedded software, autonomous cars and medical technology, as well as many other applications. Don't forget to visit this section...
Multi Dimensional Array
In simple words, an array created with more than one dimensions (size) is called as multi dimensional array.
Multi dimensional array can be of two dimensional array or three dimensional array or four dimensional array or more.
Here we discuss 2 Dimensional Array only.
Two dimensional array may be declared as following: syntax:[no-of-rows][no-of-cols]; //indexes may be more in case of 3D or more dimensional array. int a[3][4]; // declaration of 2D array, here no. of rows is 3 and no. of cols is 4.
How 2 D array is arranged in the memory, we can understand with the following diagram.
Program to take input in a matrix (2 D array) and print only the diagonal elements
#include<stdio.h> #include<conio.h> void main() { int a[3][3], i=0, j=0; printf("enter the matrix elements"); for(i=0; i<3; i++) { for(j=0; j<3; j++) { scanf("%d", &a[i][j]); } } // loop to display only the diagonal elements. for(i=0; i<3; i++) { for(j=0; j<3; j++) { if(i==j) //condition for the diagonal elements. printf("%d ", a[i][j]);
else
printf(" ");
}
printf("\n"); } } // end of main
Video/ C Introduction
Watch video in full size