Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

A matrix is a two dimensional array. It can also be descried as a pointer to a pointer or an array of pointers. In this

A matrix is a two dimensional array. It can also be descried as a pointer to a pointer or an array of pointers. In this program we will write several small utilitiy functions to test mastery of this concept. The function signatures and descriptions follow below. Also, you will want to include the stdbool.h header file for this exercise that contains the definition of a an enumerated type named bool. It should only two values: true and false. You may make the assumption that the matrix will be a square matrix meaning that the number of rows equals the number of columns in the matrix. Implement these functions: int** makeMatrix(int n); void printMatrix(int **A, int n); bool sumEqual(int **A, int **B, int n); bool isEqual(int **A, int **B, int n); int diagonal(int **A, int n); 3 int** sumMatrix(int **A, int **B, int n); int** product(int **A, int **B, int n); Please read the description of these functions carefully. The makeMatrix function should dynamically allocate memory for a matrix of size n and allow the user to enter values for each position of the matrix from left to right row by row then return the created matrix to the main function. The printMatrix function should print out a matrix row by row legibly enough so that a grader can see which number corresponds to each position of the matrix. In the sumEqual function you will sum up all the elements in each matrix and see if the sum of each array is equal to one another. The function returns true if the sums are equal or returns false if the sums do not equal one another. Function takes two matrices and a size integer. Example (sumEqual): 1 2 3 4 and 5 5 0 0 is true. In the isEqual function you will check each matrix element by element and see if each element matrix A is equal to its corresponding element in Matrix B. Return true if this is the case and false if even one element is not equal to its corresponding element in the other matrix. Function takes two matrices and a size integer. Example (isEqual): 1 2 3 4 and 1 2 3 4 is true. In the diagonal function you will calculate the product of the elements along the diagonal of the matrix and return that number. Function takes a single matrix and an integer size of that matrix and returns the product. 4 Example (diagonal): 1 2 3 4 is 4. In the sumMatrix function you will find the summation of the two matrices. Matrix summation is done element by element in the two matrices. Function takes two matrices and a size integer and returns a new matrix that is the element by element summation. Example (sumMatrix): 1 2 3 4 and 5 5 0 0 is 6 7 3 4 In the product function you will find the matrix product of multiplying two matrices together. Function takes two matrices and a size integer and returns a new matrix that is the result of matrix multiplication. Matrix multiplication is done as follows: C = A B The entries for C are: cij = Xn k=1 aikbkj where 1 i, j n and cij is the (i,j)-th entry of the matrix C. Example (product): 1 2 3 4 and 5 5 0 0 5 is 5 5 15 15 Your main function should prompt the user to input the size of the two matrices, and then create the two matrices by calling appropriate functions. Then it should call the following functions on the two matrices: sumEqual, isEqual, diagonal, sumMatrix, and product. Sample output from the program: Please enter value for size of matrix: 2 Enter values for matrix A: 1 2 3 4 Matrix A: 1 2 3 4 Enter values for matrix B: 5 5 0 0 5 5 0 0 Sum of elements in each matrix is equal A != B The product along the diagonal is: 5 The sum of matrix A and B is: 6 7 3 4 The product of matrix A and B is: 5 5 15 15

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Inference Control In Statistical Databases From Theory To Practice Lncs 2316

Authors: Josep Domingo-Ferrer

2002nd Edition

3540436146, 978-3540436140

More Books

Students also viewed these Databases questions

Question

2. What potential barriers would you encourage Samuel to avoid?

Answered: 1 week ago

Question

6. How would you design your ideal position?

Answered: 1 week ago