source code:
#include "stdafx.h"
/* display sum of two matrix*/
int _tmain(int argc, _TCHAR* argv[])
{
int a[3][3], b[3][3], c[3][3], i, j;
i = j = 0;
printf("input elements into the first matrix a[3][3]
");
for (i = 0; i < 3; i++)
{
for(j = 0; j < 3; j++)
{
scanf_s("%d", &a[i][j]);
}
}
printf("input elements into the first matrix b[3][3]
");
for (i = 0; i < 3; i++)
{
for(j = 0; j < 3; j++)
{
scanf_s("%d", &b[i][j]);
}
}
for (i = 0; i < 3; i++)
{
for(j = 0; j < 3; j++)
{
c[i][j] = a[i][j]+b[i][j];
}
}
printf("the sum of the two matrix is below:
");
for (i = 0; i < 3; i++)
{
for(j=0;j<3;j++)
{
printf("%d ",c[i][j]);
}
printf("
");
}
getchar();
}
inputs and outputs:
版权声明:本文博主原创文章,博客,未经同意不得转载。