Hey folks, I am having problems with sumMajorDiagonal. I am suppose to create that function so that the program adds the fist diagonal of the matrix, but my function its not delivering that result.
#include <iostream>
usingnamespace std;
constint SIZE = 4;
double sumMajorDiagonal(constdouble m[][SIZE], int row, int column, int i ,int j) { //create a function that sums the first diagonal in a matrix
double sumDiagonal = 0;
// Loop to sum main diagonal
for (i = 0; i<row; i++)
{
for (j = 0; j<column; j++)
{
if (i == j)
sumDiagonal += m[i][j];
}
}
return sumDiagonal;
}
int main(){
constint columns = 4;
constint rows = 4;
int columnIndex = 0;
double myArr[columns][rows], i ,j = { 0 }; //declare "myarr"
cout << "Enter a 4-by-4 matrix row by row : " << endl; //ask user value input
cout << "\nSum of main diagonal elements is " /*<< sumDiagonal*/;
return 0;
}
}