bai4-week4

// ma tran

#include<iostream.h>

#include<iomanip.h>

#include<conio.h>

class MT

{ int n,m;

float a[20][20];

public:

void nhap();

void in();

friend int ktra(MT); // co the dung ham ban o ham nay

};

void MT::nhap()

{

cout<<"nhap so dong: ";cin>>m;

cout<<"nhap so cot: ";cin>>n;

for(int i=1;i<=m;i++)

for(int j=1;j<=n;j++)

{ cout<<"nhap a["<<i<<"]["<<j<<"]= ";

cin>>a[i][j]; }

}

void MT::in()

{ cout<<setiosflags(ios::showpoint)<<setprecision(3);

for(int i=1;i<=m;i++)

for(int j=1;j<=n;j++)

{if(j==1) cout<<"

";

cout<<setw(5)<<a[i][j]; }

}

int ktra(MT b)

{ int kq; float x[20][20];

if(b.n!=b.m) kq=0;

else

{

for(int i=1;i<=b.n;i++) // thanh lap 1 ma tran don vi de so sanh

for(int j=1;j<=b.n;j++)

{ x[i][j]=0;

x[i][i]=1; }

int dem=0;

for(i=1;i<=b.n;i++)

for(int k=1;k<=b.n;k++) // chu y bien int k,ko dc viet bien j thay cho k

{

if((b.a[i][k]==x[i][k]))

dem=dem+1;

}

if(dem==b.n*b.n) kq=1;

else kq=0;

}

return(kq);

}

main()

{ MT b;

b.nhap();b.in(); //ko dc viet ktra(b)

if(ktra(b)) cout<<"

ma tran vua nhap <la> ma tran don vi";

else cout<<"

ma tran vua nhap <khong> la ma tran don vi";

getch();

}

Bạn đang đọc truyện trên: AzTruyen.Top

Tags: #business