Page 475 - computer science (868) class 11
P. 475
29 }
30 sum=pd+sd;
31 }
32 System.out.println("Sum of Diagonals:"+ sum);
33 }
34
35 //Main method
36 public static void main (String args[])
37 {
38 sumofdiagonals ob= new sumofdiagonals();
39 ob.printDiagonalSums();
40 }
41 }
The output of the preceding program is as follows:
enter the size of the matrix
3
enter the matrix elements
1
2
3
4
5
6
7
8
9
Sum of Diagonals:30
Variable Description
NAME TYPE DESCRIPTION
a[][] int[][] To store the array
i int Loop variable
j int Loop variable
sum int To store the sum of the diagonals
pd int Sum of principal array
sd int Sum of secondary diagonal
n int Size of the array
473
Internal Assessment 473

