0% found this document useful (0 votes)
18 views

Assignment-05: Course No: ME-172

This document contains code for finding the determinant of a 3x3 matrix and for multiplying two matrices. It provides the student's name, ID number, course information, and date of submission for an assignment. The code uses loops and conditional statements to calculate the determinant by finding the cofactors of the matrix and multiplying/subtracting them. It also includes code to input the matrices, output the results, and check that the matrices can be multiplied.

Uploaded by

Shaumik Rahman
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
18 views

Assignment-05: Course No: ME-172

This document contains code for finding the determinant of a 3x3 matrix and for multiplying two matrices. It provides the student's name, ID number, course information, and date of submission for an assignment. The code uses loops and conditional statements to calculate the determinant by finding the cofactors of the matrix and multiplying/subtracting them. It also includes code to input the matrices, output the results, and check that the matrices can be multiplied.

Uploaded by

Shaumik Rahman
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 5

Assignment-05

Course No: ME-172

Name of the student: Shaumik Rahman Ayon


Student ID: 201510028
Department: Mechanical Engineering
Level-1, Term-2
Section: A1

Date of submission: 24-10-2016

Finding the Determinant of a Matrix:


Code:
#include<stdio.h>
#include<math.h>
int CEM(int a[3][3],int x,int y)
{
int i,j,k=0,c,b[4];
for(i=0;i<3;i++)
{
if(i==x) continue;
for(j=0;j<3;j++)
{
if(j==y) continue;
b[k]=a[i][j];
k++;
if(k==4){break;}
}
if(k==4){break;}
}
c=b[0]*b[3]-b[1]*b[2];
return c;
}

int main()
{
int a[3][3],i,j,D;
printf("Enter the elements of your
matrix:\n");
for(i=0;i<3;i++)
for(j=0;j<3;j++)
scanf("%d",&a[i][j]);
printf("\nThe matrix you entered:");
for(i=0;i<3;i++){
printf("\n");
for(j=0;j<3;j++){
printf("%d\t",a[i][j]);}}
D=a[0][0]*CEM(a,0,0)-a[0]
[1]*CEM(a,0,1)+a[0][2]*CEM(a,0,2);
//CEM=co-efficient matrix
printf("\n\nDeterminant of the
matrix: %d\n\n",D);
return 0;
}

Output:

Matrix multiplication:
Code:
#include<stdio.h>
int main()
{
int a[20][20],b[20][20],c[20]
[20]={0},i,j,k,c1,c2,r1,r2,p,q;
printf("No of columns of
matrix1:");scanf("%d",&c1);
printf("No of rows of
matrix1:");scanf("%d",&r1);
printf("No of columns of
matrix2:");scanf("%d",&c2);
printf("No of rows of
matrix2:");scanf("%d",&r2);

printf("\nEnter the elements of


matrix2:\n");
for(i=0;i<r2;i++)
for(j=0;j<c2;j++)scanf("%d",&b[i]
[j]);
for(p=0;p<r2;p++)
for(q=0;q<c2;q++)
for(i=0;i<c1;i++)
{
c[p][q]=c[p][q]+ a[p][i]*b[i][q];
}
printf("Output:\n");
for(i=0;i<r2;i++){
for(j=0;j<c2;j++)
printf("%d \t",c[i][j]);
printf("\n");
}}
return 0;

if(c1!=r2)printf("reverse order");
else{
printf("\nEnter the elements of
matrix1:\n");
for(i=0;i<r1;i++)
for(j=0;j<c1;j++)scanf("%d",&a[i]
[j]);

Output:

You might also like