Question: So I am finding the boolean product for two matrices. If the matrices are not boolean(matrix containing ints other than 0 and 1) i need
So I am finding the boolean product for two matrices. If the matrices are not boolean(matrix containing ints other than 0 and 1) i need to exit the nested for loops and print out "The boolean product does not exist because the matrices are not boolean." Here is my section of the code for finding the boolean product:
cout << "The boolean product of the two matrices is: " << endl;
if(cols1 != rows2 )
{
cout << "The boolean product does not exist because the dimensions are incompatible." << endl;
}
else
{
for(int i = 0; i < rows1; i++)
{
for(int j = 0; j < cols2; j++)
{
if(matrix1[i][j] != 0 && matrix2[i][j] != 1)
{
cout << "The boolean product does not exist because the matrices are not boolean." << endl;
}
else
{
res = 0;
for(int k = 0; k < rows2; k++)
{
res = res+matrix1[i][k] * matrix2[k][j];
if(res>1)
{
res = 1;
}
}
cout << res << "\t";
}
}
cout << endl;
}
}
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
