Question: matrix.c matrix.c #include #include matrix.h int main() { int n = 3; int m1[n][n]; int m2[n][n]; int m3[n][n]; /* assign 3X3 matrix to following values

![int m1[n][n]; int m2[n][n]; int m3[n][n]; /* assign 3X3 matrix to following](https://dsd5zvtm8ll6.cloudfront.net/si.experts.images/questions/2024/09/66f31a9bb152d_09166f31a9b50bc6.jpg)
matrix.c![v[9] = { 8, 1, 6, 3, 5, 7, 4, 9, 2](https://dsd5zvtm8ll6.cloudfront.net/si.experts.images/questions/2024/09/66f31a9d0efd9_09266f31a9c8571e.jpg)
matrix.c
#include
#include "matrix.h"
int main() {
int n = 3;
int m1[n][n];
int m2[n][n];
int m3[n][n];
/* assign 3X3 matrix to following values
8 1 6
3 5 7
4 9 2
*/
int v[9] = { 8, 1, 6, 3, 5, 7, 4, 9, 2 };
int i, *p = &v[0];
int *p1 = &m1[0][0];
for (i = 0; i
printf(" m1: ");
display_matrix(&m1[0][0], n);
printf("msum(m1):%d ", msum(&m1[0][0], n));
printf(" m2=m1': ");
transpose_matrix(&m1[0][0], &m2[0][0], n);
display_matrix(&m2[0][0], n);
printf("msum(m2):%d ", msum(&m2[0][0], n));
multiply_matrix(&m1[0][0], &m2[0][0], &m3[0][0], n);
printf(" m3=m1*m2': ");
display_matrix(&m3[0][0], n);
printf("msum(m3):%d ", msum(&m3[0][0], n));
// vector
int v1[] = {1, 1, 1};
printf(" v1: ");
display_vector(v1, n);
printf("vsum(v1):%d ", vsum(v1, n));
int v2[n];
multiply_vector(&m1[0][0], v1, v2, n);
printf(" v2=m1*v1': ");
display_vector(v2, n);
printf("vsum(v2):%d", vsum(v2, n));
return 0;
}
Write C program matrix.h to define the prototypes of the following functions, and C program matrix.c to implement the functions of matrix.h. /* Displays vector v of n elements in one line. */ void display_vector(int *v, int n); /* * Computes and returns the sum of all elements of vector v */ int vsum(int *v, n); Displays n by n matrix m in 2D style. */ void display_matrix(int *m, n); /* * Computes and returns the sum of all elements of the n by n matrix m. */ int msum(int *m, n); /* * Transposes the n by n matrix ml and save the resulted matrix in m2. */ void transpose_matrix(int *ml, int *m2, int n); /* * Computes the matrix multiplication ml*m2 and saves the resulted matrix in m3. void multiply_matrix(int *ml, int *m2, int *m3, int n); /* * Computes n by n matrix multiplies n-vector m*vl and saves the result vector in v2. */ void multiply_vector(int *m, int *vi, int *v2, int n); Use the provided the main function program matrix main.c to test the above functions. The output is like the following Public test ml: 8 1 6 3 5 7 4 9 2 msum (ml):45 m2=m1': 8 3 4 1 5 9 6 7 2 msum (m2):45 71 m3=m1*m2': 101 53 71 83 71 53 71 101 msum (m3):675 vl: 1 1 1 vsum(v1):3 v2=m1*vi': 15 15 15 vsum (v2):45 matrix.h * your program signature */ void display_vector(int *v, int n); int vsum(int *v, int n); void display_matrix(int *m, int n); int msum(int *m, int n); void transpose_matrix(int *ml, int *m2, int n); void multiply_matrix(int *ml, int *m2, int *m3, int n); void multiply_vector(int *m, int *vi, int *v2, int n); I . #include
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
