# boolean matreix has parity property

Show 80 post(s) from this thread on one page
Page 2 of 2 First 12
• 12-28-2005
gtr_s15
can some one please fix this error for me ....

Code:

``` #include <iostream> #include <cstdlib> using namespace std; int ma(int n); int main() {     int n;            cout<<"Enter: ";     cin>>n;     int matrix[n][n]; //======================= initialise and insert values =========================     cout << "Enter the matrix by rows\n";      for(int row = 0; row < n; row++)         for(int col = 0; col < n; col++)         cin >> matrix[row][col]; //========================= sum of each row ====================================     cout<<ma(n);     system("pause"); return 0; } int ma(int n) {     int row;     int col;     int matrix[row][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;     }  }```
• 12-28-2005
spydoor
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
Code:

`ma(matrix,n)`
there is no need to cout your function call. all printing is done within the function.
• 12-28-2005
dwks
Actually, I think the OP is trying to pass main()'s matrix to ma(). As an argument.

And since ma() returns int, make it return a value.
• 12-28-2005
spydoor
Quote:

Originally Posted by dwks
Actually, I think the OP is trying to pass main()'s matrix to ma(). As an argument.

I agree, that's why I gave him an example of doing exactly that.
Passing the array and the size. Before he was just passing the size and redefining matrix locally.

Quote:

Originally Posted by dwks
And since ma() returns int, make it return a value.

I do not know what the intentions are. (It appeared he's trying to output the sum of each row)
Maybe the function definition is wrong, maybe he forgot to return a value.
All I know is right now cout<<ma(n) will output garbage.
Show 80 post(s) from this thread on one page
Page 2 of 2 First 12