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

Popular posts from this blog

javascript - How to name a jQuery function to make a browser's back button work? -

python - Django-easy-pdf: xhtml2pdf reporting reportlab 2.2+ is required, but 3.0 installed -

collision detection - C++ library for mesh to mesh intersection: what is available? -