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

Codeblocks(C Code) Question 1 Matrix Determinant: 3x3 Matrices <username>_hw8_1.

ID: 1716139 • Letter: C

Question

Codeblocks(C Code)

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  

Your function must use loops to compute the determinant. All I/O is to be done in your main() function. Example output is

The determinant of matrix

| -7 -3 3|

| 6 2 -3|

| 11 -5 8|

is 80

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 Y and 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

where and . 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.

g h i

Explanation / Answer

#include<conio.h>
#include<stdio.h>

int a[20][20],m;
int determinant(intf[20][20],inta);
int main()
{
  
int i,j;
  
printf(" Please Enter the order of the any Matrix : ");
  
scanf("%d",&m);
  
printf(" Provide the elements of the Matrix : ");
  
for(i=1;i<=m;i++)
{
for(j=1;j<=m;j++)
{
printf("a[%d][%d] = ",i,j);
scanf("%d",&a[i][j]);
}
}
  
printf(" ---------- Matrix is -------------- ");   
  
for(i=1;i<=m;i++)
{
printf(" ");
for(j=1;j<=m;j++)
{
printf(" %d ",a[i][j]);
}
}
  
printf(" ");
  
printf(" Determinant of Matrix A is %d .",determinant(a,m));
getch();

}

int determinant(int f[20][20],int x)
{
  
int pr,c[20],d=0,b[20][20],j,p,q,t;
  
if(x==2)
{
d=0;
d=(f[1][1]*f[2][2])-(f[1][2]*f[2][1]);
return(d);
}
else
{
for(j=1;j<=x;j++)
{   
int r=1,s=1;
for(p=1;p<=x;p++)
{
for(q=1;q<=x;q++)
{
if(p!=1&&q!=j)
{
b[r][s]=f[p][q];
s++;
if(s>x-1)
{
r++;
s=1;
}
}
}
}
for(t=1,pr=1;t<=(1+j);t++)
pr=(-1)*pr;
c[j]=pr*determinant(b,x-1);
}
for(j=1,d=0;j<=x;j++)
{
d=d+(f[1][j]*c[j]);
}   
return(d);
}
}

/* Matrix Multiplication using function */
#include<stdio.h >
#include<conio.h>
int i,j,k;
void main()
{
int a[10][10],b[10][10],c[10][10],m,n,p,q;
void mul(int x[10][10],int y[10][10],int z[10][10],int m,int n,int p,int q);
void read(int x[10][10],int m,int n);
void display(int x[10][10], int m,int n);
clrscr();
printf("what is the size of a Matrix A : Row and Col: ");
scanf("%d%d",&m,&n);
printf("what is the size of a Matrix B : Row and Col: ");
scanf("%d%d",&p,&q);
if(n!=p)
{
printf("Multiplication is Not Possible : Column of A must be same as Raw of B ");
}
else
{
read(a,m,n);
read(b,m,n);
mul(a,b,c,m,n,p,q);
printf("Matrix A is : ");
display(a,m,n);
printf("Matrix B is : ");

display(b,m,n);
printf("Multiplication of A and B is C : ");
display(c,m,n);
}
getch();
}
void mul(int x[10][10],int y[10][10],int z[10][10],int m,int n,int p,int q)
{
for (i=0;i<m;i++)
for(j=0;j<q;j++)
{
   z[i][j]=0;
   for(k=0;k<n;k++)
   z[i][j]+= x[i][k]*y[k][j];
}

}
void read(int x[10][10], int m,int n)
{
printf("Enter Matrix Value Row by Row ");
for (i=0;i<m;i++)
for(j=0;j<n;j++)
   scanf("%d",&x[i][j]);

}
void display(int x[10][10], int m,int n)
{
for (i=0;i<m;i++)
{
   for(j=0;j<n;j++)
   printf("%5d",x[i][j]);
   printf(" ");
}
printf(" ");

}