If I understood it right all you need to do is add elements from m1 to m2 and save the result in m3 with the element locations corresponding the ones from m1 & m2.
The way I'd solve this (if that's what should be done anyway) is to create a for loop within the function, that way you can do all the additions within a single call of the function but you need to turn in pointers as arguments
e.g. void matrixAddition(int* m1, int* m2, int* m3); but if you want to use regular int values void matrixAddition(int m1, int m2, int m3); the only option you have is to "walk" through the matrix within main() and call the function
for each individual element. I will write both versions and people can correct me if I'm wrong.
( Note: Please specify which type of function you need to make next time )
Code:
void matrixAddition(int* m1, int* m2, int* m3)
{
int i, j;
for(i=0;i<ROW;i++)
for(j=0;j<COLUMN;j++)
m3[i*ROW+j]=m1[i*ROW+j]+m2[i*ROW+j];
return;
}
Note that you are using pointers in this example so you need to turn over addresses as arguments e.g. calling a function looks like
Code:
matrixAddition(&m1[0][0], &m2[0][0], &m3[0][0]);
/*..OR..*/
matrixAddition(m1[0], m2[0], m3[0]);
And if you use the other way your main() will have 2 for loops and you'll be calling a function within second loop:
Code:
for(i=0;i<ROW;i++)
for(j=0;j<COLUMN;j++)
m3[i][j]=matrixAddition(m1[i][j], m2[i][j]);
and the function should look something like
Code:
int matrixAddition(int m1, int m2)
{
return m1+m2;
}
Note that the example with pointers is much more efficient in execution speed and memory usage.