//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);
}
hanttaha 0 Newbie Poster
daviddoria 334 Posting Virtuoso Featured Poster
hanttaha 0 Newbie Poster
daviddoria 334 Posting Virtuoso Featured Poster
hanttaha 0 Newbie Poster
daviddoria 334 Posting Virtuoso Featured Poster
ravenous 266 Posting Pro in Training
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.