Saturday, May 22, 2010

Matrix multiplication in C programming?

write(multiply) a matrix in C program which have a 3x2 matrix and 2x4 matrix. the values of the matrix are given.


matrix a=


[2 , 1


-1, 0


3, 1]


matrix b=


[3, 1, 5, -1,


4, -2, 1, 0]

Matrix multiplication in C programming?
#include%26lt;stdio.h%26gt;


void main()


{


int a[3][3],b[3][3],c[3][3];


int i,j,k,m,n,p,q;


clrscr();


printf("enter order of matrix A");


scanf("%d%d",%26amp;m,%26amp;n);


printf("enter order of matrix B");


scanf("%d%d",%26amp;p,%26amp;q);


if(n!=p)


{


printf("multiplication not possible");


}


else


{


for(i=0;i%26lt;m;i++)


{


for(j=0;j%26lt;n;j++)


{


printf("enter elements of matrix A");


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


}


}


for(i=0;i%26lt;p;i++)


{


for(j=0;j%26lt;q;j++)


{


printf("enter elements of matrix B");


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


}


}


printf("order of matrix C is %dx%d",m,q);


for(i=0;i%26lt;m;i++)


{


for(j=0;j%26lt;q;j++)


{


c[i][j]=0;


for(k=0;k%26lt;p;k++)


{


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


}


}


}


printf("matrix C is \n");


for(i=0;i%26lt;m;i++)


{


for(j=0;j%26lt;q;j++)


{


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


}


printf("\n");


}


}


getch();


}
Reply:I dont understand if you just want someone to do it for you and give you the answer or tell you how to do it. A simple search came up with http://www.edcc.edu/faculty/paul.bladek/...


No comments:

Post a Comment