-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathQ7_diagonal.c
49 lines (40 loc) · 878 Bytes
/
Q7_diagonal.c
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
/*
============================================================================
Name : lab10_a7.c
Author :
Version :
Copyright : Your copyright notice
Description : Hello World in C, Ansi-style
============================================================================
*/
#include <stdio.h>
#include <stdlib.h>
void read_2d_array(int N, int M, int arr[N][M])
{
int i, j;
for(i = 0; i < N; i++)
{
for(j = 0; j < M; j++)
scanf("%d", &arr[i][j]);
}
}
int main(void) {
int N, i, j;
int left_sum = 0, right_sum = 0;
scanf("%d",&N);
int arr[N][N];
read_2d_array(N, N, arr);
for(i = 0; i < N; i++)
{
for(j = 0; j < N; j++)
{
if(i == j)
left_sum += arr[i][j];
if(i == N-1-j)
right_sum += arr[i][j];
}
}
printf("left diagonal sum: %d\n",left_sum);
printf("right diagonal sum: %d\n",right_sum);
return 0;
}