```
//I have a problem with my program,
// the function rank to find rank of a matrix
//cannot return the result
//somebody help me to correct it!
#include<iostream.h>
#include<math.h>
#include<iomanip.h>
class matrix
{
int n,m;
double A[6][6];
public:
//.....
friend int rank(matrix);
};
int rank(matrix B)
{
int i, j, r, c;
int rankmt=B.m;
i=0;
j=0;
while(i<B.m&&j<B.n)
{
if(B.A[i][j]==0)
{
r=i+1;
while(r<B.m&&B.A[r][j]==0)
r++;
if(r==B.m)
{i++; j++; continue;}
for(c=0; c<B.n; c++)
{
double temp= B.A[r][c];
B.A[r][c]=B.A[i][c];
B.A[i][c]=temp;
}
}
}
while(i<B.m&&j<B.n)
{
if(B.A[i][j]!=0)
{
r=i+1;
while(r<B.m&&B.A[r][j]!=0)
{
for(c=0;c<B.n;c++)
B.A[r][c]-=B.A[i][c]*B.A[r][j]/B.A[i][j];
r++;
if(r==B.m)
break;
}
}
i++;
j++;
continue;
}
for(i=0;i<B.m;i++)
for(j=0;j<B.n;j++)
if(B.A[i][j]!=0)
break;
else
if(j=B.n)
rankmt--;
return rankmt;
}
void main()
{
matrix m1;
//...
cout<<rankmt(m1);
}
```