-
Notifications
You must be signed in to change notification settings - Fork 0
/
diagonal_elements_2d_array.c
73 lines (40 loc) · 1.16 KB
/
diagonal_elements_2d_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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#include<stdio.h>
#include<math.h>
int main(){
int store[3][3],i,j;
//accepting values and store in matrix form.
//i refers to row, and j refers to column.
for ( i = 0; i < 3; i++)
{ //for acceptiong values.
for ( j = 0; j < 3; j++)
{
printf("Enter Array Value: ");
scanf("%d",&store[i][j]);
}
}
//operation code.
printf("Left Diagonal Elements are: \n");
for ( i = 0; i < 3; i++)
{
for ( j = 0; j < 3; j++)
{
if (i==j)//left diagonal elemets.
{
printf("%d\t",store[i][j]);
}
}
}
printf("\nRight Diagonal Elements are: \n");
for ( i = 0; i < 3; i++)
{
for ( j = 0; j < 3; j++)
{
if (i+j==2)//right diagonal elemets. as matrix is 2x2 then i+j should equal to 2 in indexing.
{
printf("%d\t",store[i][j]);
}
}
}
printf("\n");
return 0;
}