#include<stdio.h>
#include<stdlib.h>
#include<algorithm>
#include<string.h>
#include<iostream>
using namespace std;
class Matrix
{
public:
int arr[100][100];
int m;
int n;
Matrix()
{
m=0;
n=0;
memset(arr,0,sizeof(arr));
}
Matrix operator+(const Matrix &b)const
{
Matrix temp;
temp.n=n;
temp.m=m;
for(int i=0; i<n; i++)
{
for(int j=0; j<m; j++)
{
temp.arr[i][j]=arr[i][j]+b.arr[i][j];
}
}
return temp;
}
Matrix operator-(const Matrix &b)const
{
Matrix temp;
temp.n=n;
temp.m=m;
for(int i=0; i<n; i++)
{
for(int j=0; j<m; j++)
{
temp.arr[i][j]=arr[i][j]-b.arr[i][j];
}
}
return temp;
}
Matrix operator*(const Matrix &b)const
{
Matrix temp;
temp.n=n;
temp.m=m;
for(int i=0; i<n; i++)
{
for(int j=0; j<m; j++)
{
temp.arr[i][j]=arr[i][j]*b.arr[i][j];
}
}
return temp;
}
};
int main()
{
Matrix a;
Matrix b;
a.n=4;
a.m=4;
b.n=4;
b.m=4;
for(int i=0; i<4; i++)
{
for(int j=0; j<4; j++)
{
a.arr[i][j]=4;
}
}
for(int i=0; i<4; i++)
{
for(int j=0; j<4; j++)
{
b.arr[i][j]=3;
}
}
Matrix c;
c=a-b;
for(int i=0; i<4; i++)
{
for(int j=0; j<4; j++)
{
cout<<c.arr[i][j]<<' ';
}
cout<<endl;
}
c=a+b;
for(int i=0; i<4; i++)
{
for(int j=0; j<4; j++)
{
cout<<c.arr[i][j]<<' ';
}
cout<<endl;
}
c=a*b;
for(int i=0; i<4; i++)
{
for(int j=0; j<4; j++)
{
cout<<c.arr[i][j]<<' ';
}
cout<<endl;
}
return 0;
}
矩阵基本变换
最新推荐文章于 2024-07-20 16:57:42 发布