void matrix::nhap{ coutm; coutn; forint i=0;i.
Trang 1#include<conio.h>
#include<stdio.h>
#include<math.h>
class matrix;
class vect
{
private:
float b[50];
int n;
public:
void xuat();
vect tonghang(matrix&);
void sapxep();
};
class matrix
{
private:
int m;
int n;
float a[50][50];
public:
void nhap();
void xuat();
float tong();
float max();
friend vect vect::tonghang(matrix &); };
Trang 2void matrix::nhap()
{
cout<<"\n nhap so dong cua ma tran a ";
cin>>m;
cout<<"\n nhap so cot cua ma tran a ";
cin>>n;
for(int i=0;i<m;i++)
for(int j=0;j<n;j++)
{
cout<<"\n nhap phan tu thu "<<i+1<<j+1<<" "; cin>>a[i][j];
};
};
void matrix::xuat()
{
for(int i=0;i<m;i++)
for(int j=0;j<n;j++)
cout<<"\n phan tu thu "<<i+1<<j+1<<" la : "<<a[i][j]; };
float matrix::tong()
{
float temp=0;
for(int i=0;i<m;i++)
for(int j=0;j<n;j++)
temp+=a[i][j];
return temp;
};
float matrix::max()
Trang 3float temp=0;
for(int i=0;i<m;i++)
for(int j=0;j<n;j++)
if (temp<a[i][j]) temp=a[i][j];
return temp;
};
void vect::xuat()
{
for(int j=0;j<n;j++)
cout<<"\n phan tu thu "<<j+1<<" la : "<<b[j]; };
vect vect::tonghang(matrix &mat)
{
vect temp;
temp.n=mat.m;
for(int j=0;j<mat.m;j++)
{
temp.b[j]=0;
for(int i=0;i<mat.n;i++) temp.b[j]+=mat.a[j][i];
};
return temp;
};
void vect::sapxep()
{
float temp;
for(int i=0;i<n-1;i++)
Trang 4for(int j=i+1;j<n;j++)
if(b[i]<b[j])
{
temp=b[i];
b[i]=b[j];
b[j]=temp;
};
};
int main()
{
matrix a;
vect b;
cout<<"\n nhap ma tran a ";
a.nhap();
cout<<"\n tong cac so trong ma tran a la "<<a.tong(); cout<<"\n so lon nhat trong ma tran a la "<<a.max(); cout<<"\n tong tung hang theo thu tu giam dan la "; b=b.tonghang(a);
b.sapxep();
b.xuat();
getch();
};