#include
#define ROW 3//行数
#define COL 4//列数
void PlusMatrix(int a[ROW][COL],int b[ROW][COL],int c[ROW][COL])
{
int i,j;
for(i=0;i{
for(j=0;j{
c[i][j] = a[i][j] + b[i][j];
}
}
}
void PrintMatrix(int a[ROW][COL]) //打印矩阵a的内容
{
int i,j;
for(i=0;i{
for(j=0;j{
printf("%d ",a[i][j]);
}
printf("\n");
}
}
int main()
{
int a[ROW][COL],b[ROW][COL],c[ROW][COL],i,j;
printf("input %d*%d matrix a:\n",ROW,COL);
for(i=0;i{
for(j=0;j{
scanf("%d",&a[i][j]);//输入ROW*COL的矩阵a
}
}
printf("input %d*%d matrix b:\n",COL,ROW);
for(i=0;i{
for(j=0;j{
scanf("%d",&b[i][j]);//输入ROW*COL的矩阵b
}
}
PlusMatrix(a,b,c);//a*b,结果存到c
printf("Results:\n");
PrintMatrix(c);
return 0;
}
测试: