Lets take a matrix of 4*4 i.e. int matrix [4][4];

11 12 13 14

21 22 23 24

31 32 33 34

41 42 43 44

So diagonal element of this matrix is 11, 22, 33 and 44 now see the program below

for (i = 0; i < N; i++)

for (j = 0; j < N; j++)

if (i == j)

printf(“Diagonal element is : %d\n”,matrix[i][j]);

Also we can optimize above program like given below:

for (i=0, j=0; i < N; i++, j++)

printf(“Diagonal element is : %d\n”,matrix[i][j]);

**Also interviewer can ask print diagonal element of an N*N matrix in reverse order.**

for (i=N-1, j=N-1; i >= 0; i–, j–)

printf(“Diagonal element in reverse order is : %d\n”,matrix[i][j]);