How to subtract 2 matrices using arrays in C?

Answer:

The easiest way would be to write a function that accepts two arrays and returns one.

Lets say you are working with two 2-dimensional arrays.

array<int,2>^ SubtractMatrices(int arr1[][2], int arr2[][2]);
void main()
{
int arr1[2][2] = {0,1,2,3};
int arr2[2][2] = {0,1,2,4};
array<int,2>^ newarr;
// array<int^,2>^ newarr[2][2] = SubtractMatrices(arr1, arr2);
}

array<int,2>^ SubtractMatrices(int arr1[][2], int arr2[][2])
{
array<int,2>^ newarr;
//Insert subtraction algorithm here
return newarr;
}


In this scenario you must pass the function 2 matrices, and then return a pointer to a new matrix.

Hmm, still seems to be an error in there with the return type. I'm not sure if that's the correct way to do it, I did this in Visual Studio's managed C++. Hope it helps.

First answer by J00b. Last edit by J00b. Contributor trust: 0 [recommend contributor recommended]. Question popularity: 1 [recommend question].