-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathDiagonal.c
More file actions
32 lines (26 loc) · 700 Bytes
/
Copy pathDiagonal.c
File metadata and controls
32 lines (26 loc) · 700 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#include <stdio.h>
#define MAX 10
int main() {
int matrix[MAX][MAX];
int i, j, row, col;
// Input for matrix dimensions
printf("Enter the number of rows and columns: ");
scanf("%d %d", &row, &col);
// Input for matrix elements
printf("Enter elements of the matrix:\n");
for(i = 0; i < row; i++) {
for(j = 0; j < col; j++) {
scanf("%d", &matrix[i][j]);
}
}
// Displaying diagonal elements
printf("\nDiagonal Elements of the Matrix are:\n");
for(i = 0; i < row; i++) {
for(j = 0; j < col; j++) {
if(i == j) {
printf("%d ", matrix[i][j]);
}
}
}
return 0;
}