Answered step by step
Verified Expert Solution
Question
1 Approved Answer
What I have done is below but i do not know how to impliment the .c function, please help me out! matrix.h #include #include void
What I have done is below but i do not know how to impliment the .c function, please help me out!
matrix.h
#include#include void magic_square(int *m, int n); int is_magic_square(int *m, int n); void display_matrix(int *m, int n); void transpose_matrix(int *m1, int *m2, int n); void multiply_matrix(int *m1, int *m2, int *m3, int n);
matrix.c
//--------------------------------------------------------- void magic_square(int *m, int n) { /* assign 3X3 matrix to following values 8 1 6 3 5 7 4 9 2 */ int values[9] = { 8, 1, 6, 3, 5, 7, 4, 9, 2 }; int i, len = n*n, *p = values; for (i = 0; ia2q2.c
#include "matrix.h" int main() { int n = 3; int m1[n][n]; int m2[n][n]; int m3[n][n]; int *p1 = &m1[0][0]; magic_square(p1, n); printf(" m1:"); display_matrix(p1, n); printf("is_magic_square:%d ", is_magic_square(p1, n)); int *p2 = &m2[0][0]; printf(" m1':"); transpose_matrix(p1, p2, n); display_matrix(p2, n); printf("is_magic_square:%d ", is_magic_square(p2, n)); int *p3 = &m3[0][0]; multiply_matrix(p1, p2, p3, n); printf(" m1*m1':"); display_matrix(p3, n); printf("is_magic_square:%d ", is_magic_square(p3, n)); return 0; }Write C programs named matrix.h and matrix.c containing the following the headers and implementations of following functions. 1. void magic square(int m, int n)* which generates an n by n magic square and stores it in matrix m (only n-3 is required) 2. void display matrix(int m, n)* which displays n by n matrix m in 2D style 3. inl is magic square(int m, int n)* which checks if the given matrix is a magic square, returns 1 if true otherwise0 4. void transpose_matrix(int ml, int *m2, int n) which transposes the n by n matrix ml and save the resulted matrix in m2. 5. void multiply matrix(int ml, int* m2, int m3 int n) which computes the matrix multiplication ml*m2 and saves the resulted matrix in m3 6. Use the provided the main function in a3help to create a3q2.c to test the above functions, the output is like the following public test gcc matrix.c a3q2.c -o a3q2 a3q2 m1 3 5 7 is_magic_square:1 m1' 8 34 is-magic-square: 1 m1*m1 101 71 53 71 83 71 53 71 101 is_magic_square:e
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started