Matrices In this exercise you will write several functions that operate on matri
ID: 3937359 • Letter: M
Question
Matrices In this exercise you will write several functions that operate on matrices or two-dimensional arrays. For this exercise, we will restrict our attention to square. matrices-collections of numbers with the same number of columns and rows. You will place all the function prototypes in a header file named matrix.h with their definitions in a source file named matrix.c. You should test your functions by writing a driver program, but you need not hand it in. Write a function that takes two matrices and determines if the sum of all of the elements in matrix A is equal to the sum of all the elements in matrix B. Return 0 if the summation is equal and 1 if they are not equal. Write a function that takes two matrices and determines if they are equal (all of their elements are the same). If the matrices are equal, return 0. Return 1 if they are not equal. Write a function to compute the sum of the elements along the diagonal of the matrix. Return the sum of the elements along the diagonal. Write a function to compute the summation of matrix A and B. The product of two square n times n matrices: C = A times B The entries for C are: c_ij = sigma^n _ k = 1 a_ik b_k2 where 1 lessthanorequalto i, j lessthanorequalto n and c_ij is the (i, j)-th entry of the matrix C. Write the following function to compute the product of two n times n square matrices:Explanation / Answer
#include<stdio.h>
#include<stdlib.h>
int sumEqual(int **A,int **B,int n)
{
int s1=0,s2=0,i,j;
//calculating sum of all elements in matrix A
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
{
s1=s1+A[i][j];
}
}
//calculating sum of all elements in matrix B
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
{
s2=s2+B[i][j];
}
}
if(s1==s2)return 0;//if sums are equal
else return 1;//if sums are not equal
}
int isEqual(int **A,int **B,int n)
{
int i,j;
//checking whether both matrises are equal
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
{
if(A[i][j]!=B[i][j])return 1;//if they are not equal//
}
}
return 0;//if they are equal...
}
int diagonal(int **A,int n)
{
int s1=0,s2=0,i,j;
//calculating sum of all diagonal elements
for(i=0;i<n;i++)
{
s1=s1+A[i][i];
}
return s1;//returning sum...
}
int** sumMatrix(int **A,int **B,int n)
{
int b[n][n],i,j;
//calculating summmation of matrix A and B
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
{
b[i][j]=B[i][j]+A[i][j];
}
}
return b;//returning resultant matrix
}
int** product(int **A,int **B,int n)
{
int c[n][n],i,j,k;
//calculating matrix multiplication
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
{
for(k=0;k<n;k++)
{
c[i][j]=A[i][k]*B[k][j];
}
}
}
return c;//returning resultant matrix...
}
int main()
{
return 0;
}