sum diagonal

// Hey guys, i need help displaying the sum of the major diagonal sum. I created the function that will sum the number of the main diagonal of a matrix. But, i am having problems displaying it


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
46
47
48
#include <iostream>
using namespace std;
const int SIZE = 4;
int sumdiag(const double matrix[][SIZE])
{
int i = 0, j = 0;
int sum = 0;
for (i = 0;i<4;i++)
{
for (j = 0;j<4;j++)
{
if (i == j) //()
sum += matrix[i][j];
}
}
return sum;
}


//int sumdiag(int matriz[][4]);
int main() {
int matrix[4][4];
int columnIndex, i = 0, j = 0, sumadiag = 0;

cout << "Please Enter a 4-by-4 matrix row by row: " << endl;;
for (i = 0;i<4;i++)
{
for (j = 0;j<4;j++)
{

cin >> matrix[i][j];
}
}

for (i = 0;i<4;i++)
{
for (j = 0;j<4;j++)
{
printf(" ", matrix[i][j]);
}
printf("\n");

}
cout << "The main diagonal sum of the matrix is: " << (sumadiag,matrix) << endl;// Here is my cout that should be displaying the sum 

return 0;
}
 // Put the code you need help with here. 
Last edited on
Topic archived. No new replies allowed.