# 代码填充--雨昕学矩阵

#include <iostream>
using namespace std;
class Matrix
{
public:
Matrix();
friend Matrix operator*(int k,Matrix &);
friend ostream& operator<<(ostream&,Matrix&);
friend istream& operator>>(istream&,Matrix&);
private:
int mat[2][3];
};
Matrix::Matrix()
{
for(int i=0; i<2; i++)
for(int j=0; j<3; j++)
mat[i][j]=0;
}
ostream& operator<<(ostream &out,Matrix &mat)
{
for (int i=0; i<2; i++)
{
for(int j=0; j<3; j++)
{
if(j>0) out<<" ";
out<<mat.mat[i][j];
}
out<<endl;
}
return out;
}
/*

*/

int main()
{
Matrix mat1,mat2;
int k;
cin>>k;
cin>>mat1;
mat2=k*mat1;
cout<<mat2<<endl;
return 0;
}

``````2
1 2 3
4 5 6
``````

``````2 4 6
8 10 12``````

``````#include<stdio.h>
int main()
{
int a[100][100],i,j,b;
scanf("%d",&b);
for(i=0;i<2;i++)
{
for(j=0;j<3;j++)
{
scanf("%d",&a[i][j]);
a[i][j]*=b;
}
}
for(i=0;i<2;i++)
{
for(j=0;j<2;j++)
{
printf("%d ",a[i][j]);
}
printf("%d\n",a[i][j]);
}
}``````

``````
#include <iostream>
using namespace std;
class Matrix
{
public:
Matrix();
friend Matrix operator*(int k,Matrix &);
friend ostream& operator<<(ostream&,Matrix&);
friend istream& operator>>(istream&,Matrix&);
private:
int mat[2][3];
};
Matrix::Matrix()
{
for(int i=0; i<2; i++)
for(int j=0; j<3; j++)
mat[i][j]=0;
}
ostream& operator<<(ostream &out,Matrix &mat)
{
for (int i=0; i<2; i++)
{
for(int j=0; j<3; j++)
{
if(j>0) out<<" ";
out<<mat.mat[i][j];
}
out<<endl;
}
return out;
}
Matrix operator*(int  k,Matrix &mat)
{
Matrix result;
for(int i=0; i<2; i++)
for(int j=0; j<3; j++)
{
result.mat[i][j]=k*mat.mat[i][j];
}
return result;
}
istream& operator>>(istream &in,Matrix &mat)
{
for(int i=0; i<2; i++)
for(int j=0; j<3; j++)
in>>mat.mat[i][j];
return in;
}
int main()
{
Matrix mat1,mat2;
int k;
cin>>k;
cin>>mat1;
mat2=k*mat1;
cout<<mat2<<endl;
return 0;
}
``````