java - How can we find the sum of the diagonal elements and then store in different array? -
i want sum of 2d matrix , store in array, e.g. if have a[][][] a[0][1] stored in array b[] @ b[1],a[0][1]+a[1][0], @ b[2] a[0][2]+a[1][1]+a[2][0] ... , on.
you can reverse column count
sum=0; column_count=b.length-1; for(i=0; i<b.length;i++) { sum+=b[i][i]; sum+=b[i][column_count]; column_count--; } print sum;
Comments
Post a Comment