|
|
|
/* Program of addition,substraction,and multiplication of matrix */
#include #include void read_mat(int m,int n,int a[5][5]) { int i,j; for(i=0;i { for(j=0;j { printf("\n Enter element :"); scanf("%d",&a[i][j]); } } void print_mat(int m,int n,int a[5][5]) { int i,j; for(i=0;i { for(j=0;jprintf(" %d",a[i][j]); printf("\n"); } } void add_mat(int m,int n,int a[5][5],int b[5][5],int s[5][5]) { int i,j; for(i=0;i { for(j=0;j { s[i][j]=a[i][j]+b[i][j]; } } } void sub_mat(int m,int n,int a[5][5],int b[5][5],int sd[5][5]) { int i,j; for(i=0;i { for(j=0;j { sd[i][j]=a[i][j]-b[i][j]; } } } void mul_mat(int m,int n,int q,int a[5][5],int b[5][5],int mt[5][5]) { int i,j,k; for(i=0;i { for(j=0;j { mt[i][j]=0; for(k=0;k { mt[i][j]=mt[i][j]+a[i][k]*b[k][j]; } } } } void main() { int m,n,p,q,i,j,a[5][5],b[5][5],s[5][5],sd[5][5],mt[5][5]; printf("\n Enter order of first matrix :"); scanf("%d%d",&m,&n); printf("\n Order of second matrix :"); scanf("%d%d",&p,&q); if((m!=p)&&(n!=q)) printf("\n Matrices are imcompatable for addotion and substraction"); else { printf("\n Read the element of first matrix "); read_mat(m,n,a); printf("\n Read the element of second matrix "); read_mat(p,q,b); printf("\n FIRST MATRIX IS ......\n"); print_mat(m,n,a); printf("\n SECOND MATRIX IS ....\n"); print_mat(p,q,b); add_mat(m,n,a,b,s); printf("\n AFTER ADDITION MATRIX IS ....\n"); print_mat(m,n,s); sub_mat(m,n,a,b,sd); printf("\n AFTER SUBSTRACTION MATRIX IS ....\n"); print_mat(m,n,sd); } if(p==q) { mul_mat(m,n,q,a,b,mt); printf("\n AFTER MULTIPLICATION MATRIX IS ....\n"); print_mat(m,q,mt); } else printf("\n Matrices are incompatible for multiplication "); getch(); }
|
No responses found. Be the first to respond and make money from revenue sharing program.
|