Write a program to check whether the diagonal elements of a (4*4) matrix are all Zero.

This answer is restricted. Please login to view the answer of this question.

Login Now
#include <stdio.h>
#define SIZE 4

int main(){
    int matrix[SIZE][SIZE], i, j;

    // Read the data into the matrix
    printf("Enter Matrix Data: \n");
    for(i=0; i < SIZE; i++){
        printf("Enter Data of row %d:\n", i+1);
        for(j=0; j < SIZE; j++){
            scanf("%d", &matrix[i][j] );

    /** Check If Disagonal Element are same*/
    i = matrix[0][0];
    j = 0;
    while(j < SIZE ){
        if(matrix[j][j] != i){

    //if j is equal to the size of the matrix then voila! diagonal entries match.
    if(j == SIZE){
        printf("The diagonal is the same\n");
        printf("The diagonal is not the same. %d, %d\n");

    return 0;


If you found any type of error on the answer then please mention on the comment or report an answer or submit your new answer.
Leave your Answer:

Click here to submit your answer.

  Loading . . .