bai4-week3

#include<iostream.h>

#include<iomanip.h>

#include<conio.h>

class MT

{ int n,m;

float a[20][20];

public:

void nhap();

void in();

int ktra();

};

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 MT::ktra()

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

if(n!=m) kq=0;

else

{

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

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

{ x[i][j]=0;

x[i][i]=1; }

int dem=0;

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

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

{

if((a[i][k]-x[i][k])==0)

dem=dem+1;

}

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

else kq=0;

}

return(kq);

}

main()

{ MT b;

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

if(b.ktra()) 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