I have to use the header given to help find the sum of the each of the columns, the first issue is that the matrix does not continue it ends after one line and give a weird number/letter code. Second isan issue for when I cout.
#include <iostream>
using namespace std;
const int SIZE = 4;
double sumMajorDiagonal(const double m[][SIZE])
{
double sum = 0;
for (int i = 0; i < SIZE; i++)
sum += m[i][i];
return sum;
}
int main()
{
double matrix[SIZE][SIZE];
cout << "Enter a 4 by 4 matrix row by row: " << endl;
for (int i = 0; i < SIZE; i++)
for (int j = 0; j < SIZE; j++)
cin >> matrix[i][j];
cout << "Sum of the elements in the major diagonal is "
<< sumMajorDiagonal(matrix) << endl;
return 0;
}
#include <iostream>
using namespace std;
int main()
{
const int ROWSIZE = 4;
const int COLUMNSIZE = 3;
double matrix[ROWSIZE][COLUMNSIZE];
cout << "Enter a 3-by-4 matrix row by row: " << endl;
for (int i = 0; i < ROWSIZE; i++)
{
for (int j = 0; j < COLUMNSIZE; j++)
{
cin >> matrix[i][j];
}
}
return 0;
double sumColumn(const double m[][SIZE], int rowSize, int columnIndex)
{
columnIndex = 0;
for (int i = 0; i < SIZE; i++)
{
for (int j = 0; j < columnIndex; j++)
columnIndex += m[i][j];
}
return columnIndex;
}
int main()
{
const int ROWSIZE = 4;
const int COLUMNSIZE = 3;
double m[ROWSIZE][COLUMNSIZE];
cout << "Enter a 3-by-4 matrix row by row: " << endl;
double sumColumn(const double m[][SIZE], int rowSize, int columnIndex);
for (int i = 0; i < ROWSIZE; i++)
{
for (int j = 0; j < COLUMNSIZE; j++)
{
cin >> m[i][j];
cout << "Sum of the elements at column = " << sumColumn(m , COLUMNSIZE) << endl;
}
}
return 0;
}
This is the code sorry about that.