Calculating the sum of diagonal elements and then finding the difference in C++
![Image](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiR5ZyxZ5JFK23haWSxk-YMBf2Xr1rbpJRkmmTN1NPB3yl2m0VBCvyrxOcil9aq3FoeT12ZQM5TilRyjtErFgYe3tnIiLZE2wdteXDO5fTD1Id5o-NaANkgwnGYpfvqG6GIgthEuuDY0AAemJARXZyzuuHQdvSsTonJc92ZwK6ZPVMT4F14K2o91Zr1ePg/w639-h93/CS%20ka%20Gyan%20footer.png)
#add of diagonal of 2d array #include <iostream> using namespace std; #include <math.h> int main() { int arr[3][3] = {1, 4, 2, 5, 2, 8, 2, 5, 9}; int sum1 = 0 , sum2 = 0; for (int i = 0; i < 3; i++) { sum1 += arr[i][i]; sum2 += arr[i][2 - i]; } int d = abs(sum1 - sum2); cout << "Sum of diagonal1: " << sum1 << endl; cout << "Sum of diagonal2: " << sum2 << endl; cout << "Diff between the sums: " << d << endl; return 0; }