My issue
sum of diagonal
My code
#include <stdio.h>
int main() {
int N;
// Input the size of the matrix
scanf("%d", &N);
int matrix[N][N];
int primaryDiagonalSum = 0;
int secondaryDiagonalSum = 0;
// Input elements of the matrix
for (int i = 0; i < N; i++) {
for (int j = 0; j < N; j++) {
scanf("%d", &matrix[i][j]);
}
}
// Calculate the sums of the primary and secondary diagonals
for (int i = 0; i < N; i++) {
primaryDiagonalSum += matrix[i][i]; // Primary diagonal
secondaryDiagonalSum += matrix[i][N - 1 - i]; // Secondary diagonal
}
// Output the sums of the diagonals
printf("%d\n", primaryDiagonalSum + secondaryDiagonalSum);
return 0;
}
Learning course: BCS301: Data structures
Problem Link: https://www.codechef.com/learn/course/abesit-dsa/ABESITDS09/problems/MATDIAGSUM