[35 pts] Function addMat takes in 2 square matrices (matA and matB) of size n x
ID: 3741134 • Letter: #
Question
[35 pts] Function addMat takes in 2 square matrices (matA and matB) of size n x n. Complete the addMat function with the following specifications d. i. Allocate annxn integer matrix and have it pointed by pointer matR. ii. Perform matrix addition: matR matA mate Be aware of the data type declared in the function. You must not use any array annotation, such as [], in this problem. Any use of array iv. v. will result in receiving 0 point. int * * addMat( int** matA, int** matB, int n) { in. * * matA; //Hint : A double pointer i3 a pointer to pointer3 //Allocate memory here: //Add matrices here: //Return resulting ratizx here:Explanation / Answer
The code is
int **addMat(int **matA,int **matB,int n)
{
int **matR=(int **)malloc(sizeof(int*)*n);
int i,j;
for (i=0;i<n;i++)
*(matR+i)=(int*)malloc(sizeof(int)*n);
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
*(*(matR+i)+j)=*(*(matA+i)+j)+*(*(matB+i)+j);
}
return matR;
}
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.