function to sum the diagonal of a matrix

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.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#include <iostream>

using namespace std;

const int SIZE = 4;
double sumMajorDiagonal(const double 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(){
	const int columns = 4;
	const int 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;
}    
    }
closed account (48T7M4Gy)
total = 0;
for(int i = 0 etc)
total += matrix[i][i];
closed account (48T7M4Gy)
http://www.cplusplus.com/forum/beginner/212598/
Topic archived. No new replies allowed.