Write a C program that computes the sum of boundary elements and the absolute difference between the diagonals of a square matrix.
Example Inputs & Outputs:
Enter the size of the matrix: 3 Enter the matrix elements: 1 2 3 4 5 6 7 8 9 Boundary sum: 40 Diagonal difference: 0
Enter the size of the matrix: 4 Enter the matrix elements: 5 8 12 3 7 11 4 9 10 6 14 2 3 9 8 15 Boundary sum: 91 Diagonal difference: 29
To solve this problem, follow these steps:
for (j = 0; j < n; j++) { boundary_sum += matrix[0][j] + matrix[n-1][j]; }
for (i = 1; i < n-1; i++) { boundary_sum += matrix[i][0] + matrix[i][n-1]; }
for (i = 0; i < n; i++) { primary_sum += matrix[i][i]; }
for (i = 0; i < n; i++) { secondary_sum += matrix[i][n-1-i]; }
diagonal_diff = abs(primary_sum - secondary_sum);
boundary_sum = sum of first and last rows + sum of first and last columns (excluding corners)
diagonal_diff = abs(primary_sum - secondary_sum);
Task: Implement the above logic and write a C program to calculate the boundary sum and diagonal difference.