# Thread: boolean matreix has parity property

1. ## boolean matreix has parity property

hi, i have a problem with this, please be sure that this is not to ask for answer, this is to ask for what i want to do

actually i have written some of the code but i have stuck with ...can someone give me some advice on what should i do. i am not asking for answer...

this is my code:

Code:
```#include <iostream>
#include <cstdlib>
using namespace std;

int main()
{
int n;

cout<<"Please enter how many integers per line [ 1 < 100 ]: ";
cin>>n;

int row = n;
int col = n;
int matrix[row][col];

//assign limitation between values

if(n<100 && n>0)
{
//initialize and insert values into the matrix

for(int row = 0; row < n; row++)
{
for(int col = 0; col < n; col++)

cin>>matrix[row][col];
}

//sum each row

for(int row = 0; row < n; row++)
{
int sumRow = 0;

for(int col = 0; col < n; col++)
{
sumRow = sumRow + matrix[row][col];
cout<<"sum of row "<<row+1<<" = "<<sumRow<<endl;
}
//sum each column

for(int col = 0; col < n; col++)
{
int sumColumn = 0;

for(int row = 0; row < n; row++)

sumColumn = sumColumn + matrix[row][col];
cout<<"sum of column "<<col+1<<" = "<<sumColumn<<endl;
}

//check parity

}
else
{
return 1;
}
system("pause");
return 0;
}```

2. Originally Posted by gtr_s15
hi, i have a problem with this, please be sure that this is not to ask for answer, this is to ask for what i want to do

actually i have written some of the code but i have stuck with ...can someone give me some advice on what should i do. i am not asking for answer...

this is my code:

Code:
```    int n;

cout<<"Please enter how many integers per line [ 1 < 100 ]: ";
cin>>n;

int row = n;
int col = n;
int matrix[row][col];```
Pick a language that might be either C or C++ for starters. What you have posted is neither C++98 nor C99 but some bast^H^H^H^H extension lying elsewhere.

Also, you may want to state what you expect an output to be for a specific input.

Oh, and you might want to make sure that your curly braces match up.

ALWAYS USE FULL BRACING. ALWAYS! AND ESPECIALLY WHEN STARTING!!!

3. well it is C++

the code is aim to reads in a matrix and checks if it has the parity property. if not, the parity property can be established by changing only one bit. if it is not possbile either, the matrix should be classfied as corrupt..

for example:

1 0 1 0
0 0 0 0
1 1 1 1
0 1 0 1

1 0 1 0
0 0 1 0
1 1 1 1
0 1 0 1

1 0 1 0
0 1 1 0
1 1 1 1
0 1 0 1

the output :

OK
change bit(2,3)
corrupt

hope u understand what i mean

4. You can only have constants for array sizes, they can't be variable.
You will have to use dynamic memory.

Code:
``` int n;
int *matrix;
cout<<"Please enter how many integers per line [ 1 < 100 ]: ";
cin>>n;
matrix = new int[n];```

5. the code is aim to reads in a matrix and checks if it has the parity property. if not, the parity property can be established by changing only one bit. if it is not possbile either, the matrix should be classfied as corrupt..
Have you written code to check the matrix for the parity property? To do this, you need to add up each row and column. Try this, then post some code if it's not working.

I would highly recommend you break up you program into functions. For example make a function to check for parity. This will make it much easier.

6. ok i try and will put up my code, thank you all

7. Originally Posted by jlf029
You can only have constants for array sizes, they can't be variable.
You will have to use dynamic memory.

Code:
``` int n;
int *matrix;
cout<<"Please enter how many integers per line [ 1 < 100 ]: ";
cin>>n;
matrix = new int[n];```

hi, i dont understand this part... can you please explain.

8. You cant put variables in arrays unless they are constants.

const int SIZE = 10;
int array[SIZE][SIZE];

or dynamically
int **matrix;
int n;
matrix = new int*[n];
for(int i=0;i<n;i++)
matrix[i] = new int[n];

9. thanks but it doesnt work..

10. You mean the dynamic array code? Well, you have to set n to something:
Code:
```int **matrix;
int n;
// set n
matrix = new int*[n];
for(int i=0;i<n;i++)
matrix[i] = new int[n];```

11. Originally Posted by dwks
You mean the dynamic array code? Well, you have to set n to something:
Code:
```int **matrix;
int n;
// set n
matrix = new int*[n];
for(int i=0;i<n;i++)
matrix[i] = new int[n];```

this works on this code
Code:
```#include <iostream>
#include <cstdlib>
using namespace std;

int main()
{
int **matrix;
int n = 4;

cout<<"Enter: ";
cin>>n;

matrix = new int*[n];
for(int i=0;i<n;i++)
matrix[i] = new int[n];

cout<<matrix[0];

system("pause");
return 0;
}```
but what does this code do as i do this cout<<matrix[0]; ,
this comes out from the screen 0x3d3af0...

12. Originally Posted by swoopy
Have you written code to check the matrix for the parity property? To do this, you need to add up each row and column. Try this, then post some code if it's not working.

I would highly recommend you break up you program into functions. For example make a function to check for parity. This will make it much easier.
hi this is the code that i make into function but some error, can you please help 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;
}
}```

13. You need to pass your matrix as a parameter as well.
All you're doing is summing some uninitialised local matrix, not the one you input your data to.

14. Originally Posted by gtr_s15
this works on this code
Code:
```#include <iostream>
#include <cstdlib>
using namespace std;

int main()
{
int **matrix;
int n = 4;

cout<<"Enter: ";
cin>>n;

matrix = new int*[n];
for(int i=0;i<n;i++)
matrix[i] = new int[n];

cout<<matrix[0];

system("pause");
return 0;
}```
but what does this code do as i do this cout<<matrix[0]; ,
this comes out from the screen 0x3d3af0...
You're printting an address. Try initializing and printing matrix[0][0].

15. Code:
```    int row;
int col;
int matrix[row][col];```
row and col are uninitialized, so that's probably not what you want.