The question are with reference to the C Programming Language Write a function m
ID: 3751261 • Letter: T
Question
The question are with reference to the C Programming Language
Write a function matrixFunction( ) that takes three matrices A, B and C, each of size n x n. The output matrix is
related to the input matrices as follows:
Cij = k*(Aij *Bij)
You can assume n=4, and k=2.5.
You will need to write a function matrixFunction ( ) that takes the three matrices, A, B, C and n as input.
Also, you will need a second function printMatrix() that takes a 2D matrix and prints out its elements.
The elements in the matrices are expected to be real numbers.
Here, you only need to do the following:
(c1) Write the function prototype
(c2) Show how the two function (matrixFunction( ) and printMatrix( ) ) will be called
(c3) Write the function definition for the function matrixFunction( )
(c4) Write the function definition for the function printMatrix() .
Explanation / Answer
Answers given to each question separately
(c1) Write the function prototype
void matrixFunction(double A[][4], double B[][4], double C[][4]);
void printMatrix(double A[][4]);
--------------------------------------------------------
(c2) Show how the two function (matrixFunction( ) and printMatrix( ) ) will be called
Assuming A, B, and C are declared as 2D 4x4 arrays as follows, the function calls are shown below
double A[4][4] = {{1, 2, 3, 4}, {2, 3, 4, 5} , {3, 4, 5, 6}, {4, 5, 6, 7}};
double B[4][4] = {{10, 20, 30, 40}, {20, 30, 40, 50} , {30, 40, 50, 60}, {40, 50, 60, 70}};
double C[4][4];
matrixFunction(A, B, C);
printMatrix(C);
--------------------------------------------------------
(c3) Write the function definition for the function matrixFunction( )
#include <math.h>
void matrixFunction(double A[][4], double B[][4], double C[][4])
{
int i, j;
double k = 2.5;
for(i = 0; i < 4; i++)
{
for(j = 0; j < 4; j++)
{
C[i][j] = k * sqrt(A[i][j] * B[i][j]);
}
}
}
--------------------------------------------------------
(c4) Write the function definition for the function printMatrix() .
void printMatrix(double A[][4])
{
int i, j;
for(i = 0; i < 4; i++)
{
printf(" ");
for(j = 0; j < 4; j++)
{
printf("%f ", A[i][j]);
}
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.