#include <stdio.h>
#include <stdlib.h>
#define M 3
#define N 3
void input(int a[][N], int m) {
int i, j;
for (i = 0; i < m; i++)
for (j = 0; j < N; j++)
scanf("%d", &a[i][j]);
}
void output(int a[][N], int m) {
int i, j;
for (i = 0; i < m; i++) {
for (j = 0; j < N; j++)
printf("%5d", a[i][j]);
printf("/n");
}
}
void sum(int a[][N], int b[][N], int c[][N], int m) {
int i, j;
for (i = 0; i < m; i++)
for (j = 0; j < N; j++)
c[i][j] = a[i][j] + b[i][j];
}
int main() {
int matrix1[M][N], matrix2[M][N], matrix3[M][N];
printf("输入第一个矩阵的各元素:\n");
input(matrix1, M);
printf("输入第2个矩阵的各元素:\n");
input(matrix2, M);
sum(matrix1, matrix2, matrix3, M);
printf("两个矩阵的和:\n");
ouuput(matrix3, M)
}
标签:int,++,数组,printf,多维,matrix2,matrix3,matrix1
From: https://blog.51cto.com/u_16030624/7414418