-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patharray.c
56 lines (51 loc) · 1.13 KB
/
array.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
50
51
52
53
54
55
56
// Program to find the sum of principle and diagonal elements of a Matrix
#include <stdio.h>
#include <stdlib.h>
int main()
{
int A[10][10],n,m,i,j;
int sum1=0,sum2=0;
printf("Enter the order of matrix : ");
scanf("%d %d", &n, &m);
printf("Enter the elements of Matrix :\n ");
for (i=0; i<n; i++)
{
for(j=0; j<n; j++)
{
printf("\nEnter A%d%d element : ", i+1, j+1);
scanf("%d", &A[i][j]);
}
}
printf("Matrix is :\n");
for (i=0; i<n; i++)
{
for (j=0; j<n; j++)
{
printf("\t%d", A[i][j]);
}
printf("\n");
}
for (i=0; i<n; i++)
{
for (j=0; j<n; j++)
{
if (i==j)
{
sum1+=A[i][j];
}
}
}
printf("\nSum of Principle Diagonal elements is %d\n", sum1);
for (i=0; i<n; i++)
{
for (j=0; j<n; j++)
{
if (i+j+2==n+1)
{
sum2+=A[i][j];
}
}
}
printf("\nSum of Secondary Diagonal elements is %d\n", sum2);
return 0;
}