Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Codeblocks(C Code) ONLY USE #stdio.h Question 1 Matrix Determinant: 3x3 Matrices

ID: 3672261 • Letter: C

Question

Codeblocks(C Code) ONLY USE #stdio.h

Question 1

Matrix Determinant: 3x3 Matrices                   <username>_hw8_1.c

Write a program that calls a function in order to compute the determinant of 3x3 array X. Finding the determinant involves expanding along a row or column and summing the weighted determinants of the sub-matrices obtained by omitting that particular row and column. For example, expanding along the top row and computing the determinants of the sub-matrices directly, we have that the determinant for 3x3 X as defined below is

Question 2

Matrix Multiplier: Matrices 3x3 <username>_hw8_2.c

Write a program that calls a function in order to multiple 3x3 array X by 3x3 array Yand puts the result into 3x3 array Z such that Z=X*Y.

Matrix multiplication involves cross-products between rows and columns; written in summation form (maintaining consistency with the C numbering convention of starting from zero), we have that

All I/O is the be done in your main() function, which must then call a function to compute and return the matrix multiplication result. Hint: a triplet of for loops may be necessary in your function. Test your code with the following example:

g h i

Explanation / Answer

Program to compute determinant:

#include <stdio.h>

void determinant(int a,int b,int c, int d, int e,int f,int g, int h ,int i);

int main()

{

    int D[3][3];

    int row, col;

    int a, b, c, d, e, f, g, h, i;

    long det;

   printf("Please enter elements in matrix of size 3x3: ");

    for(row=0; row<3; row++)

    {

        for(col=0; col<3; col++)

        {

            scanf("%d", &D[row][col]);

        }

    }

//STORE THE VALUE OF ROW AND COLUMN IN VARIABLE//

    a = D[0][0];

    b = D[0][1];

    c = D[0][2];

    d = D[1][0];

    e = D[1][1];

    f = D[1][2];

    g = D[2][0];

    h = D[2][1];

    i = D[2][2];

determinant(a,b,c,d,e,f,g,h,i);//FUNCTION CALL//

return(0);

}

//DEFINE DETERMINANT FUNCTION//

void determinant(int a,int b,int c, int d, int e,int f,int g, int h ,int i)

{

    long det;

det= (a*(e*i - f*h)) - (b*(d*i - f*g)) + (c*(d*h - e*g));

printf("Determinant of matrix D = %ld ", det);

}

MATIRICS MULTIPLICATION OF GIVEN VALUES :

#include <stdio.h>

void mult(int X[][3], int Y[][3], int multiply[][3]);

void display(int a[][3]);

int main()

{

    int p[3][3] = {{2, 1, 3},{-1, 0, 4}, {3, -6, 5}};

    int q[3][3] = {{-7, 8, 3}, {-3, 3, 0}, {-5, -1, 2}};

    int r[3][3] = { 0 };

    mult(p, q, r);

    display(r);

}

//DEFINE MULTIPLY FUNCTION//

void mult(int X[][3], int Y[][3], int multiply[][3])

{

    int i, j, k;

    for(i = 0; i < 3; i++)

    {

            for(j = 0; j < 3; j++)

            {

                    for(k = 0; k < 3; k++)

                    {

                            multiply[i][j] += X[i][k] * Y[k][j];

                    }

            }

    }

}

//DEFINE DISPLAY FUNCTION//

void display(int a[][3])

{

    int i, j;

    for (i = 0; i < 3; i++)

    {

            for(j = 0; j < 3; j++)

            {

                    printf("%d ", a[i][j]);

            }

            printf(" ");

    }

}