It seems like this has all already been stated but....
int matrix[n][n];
You cannot declare an array with variables for size.
Use new
Code:
int **matrix;
int n;
cout << "Enter: ";
cin >> n;
matrix = new int*[n];
for(int i=0;i<n;i++) {
matrix[i] = new int[n];
}
//======================= initialise and insert values =========================
You will also want to delete this memory when you are done with it.
You need to pass matrix to your sum function. Currently you are summing an uninialized local array.
Code:
int ma(int **matrix, int n)
{
int row;
int col;
for(row = 0; row < n; row++)
{
int sumRow = 0;
for(col = 0; col < n; col++)
sumRow = sumRow + matrix[row][col];
cout << "sum of row "<<row+1<<" = "<<sumRow<<endl;
}
}
call ma like
there is no need to cout your function call. all printing is done within the function.