Sololearn: Learn to Code
New course! Every coder should learn Generative AI!
Try a free lesson
+ 3
#include <iostream> using namespace std; int main() { int n; cin>>n; int a[n][n]; for(int i=0;i<n;i++) { for(int j=0;j<n;j++) { cin>>a[i][j]; } } //sum the elements int sum=0; for(int i=0;i<n;i++) { sum+=(a[i][i]+a[i][n-1-i]); } if(n%2) { n/=2; sum-=a[n][n]; } cout<<"sum of elements ="<<sum; return 0; }
8th Jan 2017, 4:30 AM
Rishabh Agrawal
Rishabh Agrawal - avatar