#include <stdio.h>
int main()
{
int N, a[10][10], b[10][10];
scanf("%d", &N);
int i, j;
for (i = 0; i < N; i++)
for (j = 0; j < N; j++)
scanf("%d", &b[i][j]);
int k = 1;
char c;
scanf("\n%c",&c);
while (k == 1)
{
for (i = 0; i < N; i++)
for (j = 0; j < N; j++)
scanf("%d",&a[i][j]);
switch (c)
{
case '+':
for (i = 0; i < N; i++)
for (j = 0; j < N; j++)
b[i][j]=b[i][j]+a[i][j];
break;
case '-':
for (i = 0; i < N; i++)
for (j = 0; j < N; j++)
b[i][j]=b[i][j]-a[i][j];
break;
}
scanf("\n%c", &c);
if(c=='#')
break;
}
for (i = 0; i < N; i++)
{
for (j = 0; j < N; j++)
printf("%5d", b[i][j]);
printf("\n");
}
return 0;
}
可以通过for循环来实现