Aim: - To perform the following operation in Matrix

1. Addition 2. Subtraction        3. Multiplication    4. Transpose

 

#include<stdio.h> #include<conio.h> void main()

{

int a[3][3],b[3][3],c[3][3],d[3][3],i,j,k;

clrscr();

printf("Enter the data in Matrix A"); for(i=0;i<3;i++)

{

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

{

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

}

}

printf("Enter the data in Martix B"); for(i=0;i<3;i++)

{

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

{

scanf("%d",&b[i][j]);

}

}

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

{

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

{

c[i][j]=a[i][j]+b[i][j];

}

}

printf("Addition of two Matrix A and B is\n"); for(i=0;i<3;i++)

{

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

{

printf("%d\t",c[i][j]);

}

printf("\n");

}

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

{

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

{

c[i][j]=a[i][j]-b[i][j];

}

}

printf("Subtraction of two Matrix A and B is\n"); for(i=0;i<3;i++)

{

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

{

printf("%d\t",c[i][j]);

}

printf("\n");

}

printf("Transpose of Matrix C is\n"); for(i=0;i<3;i++)

{

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

{

d[j][i]=c[i][j];

}

}

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

{

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

{

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

}

printf("\n");

}

printf("Multiplication of Matrix A and B is\n");

 

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

{

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

{ c[i][j]=0;

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

{

c[i][j]=c[i][j]+a[i][k]*b[k][j];

}

}

}

printf("\n"); for(i=0;i<3;i++)

{

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

{

printf("%d\t",c[i][j]);

}

printf("\n");

}

 getch();

}