Dec 10, 2013 at 4:15pm UTC
how to use bool to identified a identity matrix
Dec 10, 2013 at 4:27pm UTC
You need to define a 2D array of bool.
Dec 10, 2013 at 4:36pm UTC
#include <fstream>
#include<iostream>
#include <iomanip>
#include <stdlib.h>
#include <conio.h>
#include <cmath>
bool check( int[][3] , int);
using namespace std;
#define size 3
void main()
{
int b=0;
int c[3][3] ={ {1,0,0},{0,1,0},{0,0,1}};
if(check(c,b))
cout << "It is a identity function";
else
cout << "not";
_getch();
}
bool check ( int d[][3], int e)
{
bool flag= false;
for(int i=0; i<3; i++){
for (int j=0; j<3; j++){
if ( !(i=j)){
if( d[i][i]== e )
flag=true;
else
return false;
}
else{
if(d[i][j]== d[i][j])
flag=true;
else
return false;
}
}
return flag;
}
}
Dec 10, 2013 at 4:37pm UTC
Is it any wrong with my program?
I can just cout not,i fail to cout identity function.
Dec 10, 2013 at 4:37pm UTC
#include <fstream>
#include<iostream>
#include <iomanip>
#include <stdlib.h>
#include <conio.h>
#include <cmath>
bool check( int[][3] , int);
using namespace std;
#define size 3
void main()
{
int b=0;
int c[3][3] ={ {1,0,0},{0,1,0},{0,0,1}};
if(check(c,b))
cout << "It is a identity function";
else
cout << "not";
_getch();
}
bool check ( int d[][3], int e)
{
bool flag= false;
for(int i=0; i<3; i++){
for (int j=0; j<3; j++){
if ( !(i=j)){
if( d[i][i]== e )
flag=true;
else
return false;
}
else{
if(d[i][j]== d[i][j])
flag=true;
else
return false;
}
}
return flag;
}
}
Dec 10, 2013 at 4:38pm UTC
Is it any problem with this program?
i can just cout not.
Dec 10, 2013 at 5:55pm UTC
Have you tried stepping through it with a debugger? That will show you which conditions are evaluating to true or false, which will show you what's going wrong.
Also, please use code tags when posting code, to make it readable.
Dec 11, 2013 at 9:46am UTC
sorry,i solve it already.Thank you,is syntax error.