code:
Can't Copy and Paste this?
Click here for a copy-and-paste friendly version of this code!
//
/* Jason Boxall 1/14/96 CSC 131 Lab #6 */
/* this program adds 2 matrices and prints the results */
#include
void addArray(int [][2],int [][2],int [][2]);
void printArray(int [][2]);
void main()
{
int arrayA[2][2]={ {1,2},{3,4} },
arrayB[2][2]={ {-3,-1},{5,6} },
arrayC[2][2];
printf("When matrix #1\n");
printArray(arrayA);
printf("is added to matrix #2\n");
printArray(arrayB);
printf("the result is:\n");
addArray(arrayA,arrayB,arrayC);
printArray(arrayC);
}
void addArray(int a[][2],int b[][2],int c[][2])
{
int i=0,j=0;
for(i=0;i<2;++i)
for(j=0;j<2;++j)
c[i][j]=a[i][j]+b[i][j];
}
void printArray(int a[][2])
{
int m=0,n=0;
for(m=0;m<2;++m)
{
for(n=0;n<2;++n)
printf("%3d ",a[m][n]);
printf("\n");
}
}