English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

4 answers

U haven't mentioned about the language, anyways I'm giving u the solution using C-codes, hope u're familiar with C. Check it out.

/*demo of matrix-multiplication*/
#include
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",&m,&n);
printf("enter order of matrix B");
scanf("%d%d",&p,&q);
if(n!=p)
{
printf("multiplication not possible");
}
else
{
for(i=0;i {
for(j=0;j {
printf("enter elements of matrix A");
scanf("%d",&a[i][j]);
}
}
for(i=0;i {
for(j=0;j {
printf("enter elements of matrix B");
scanf("%d",&b[i][j]);
}
}
printf("order of matrix C is %dx%d",m,q);
for(i=0;i {
for(j=0;j {
c[i][j]=0;
for(k=0;k {
c[i][j]=c[i][j] + a[i][k] * b[k][j];
}
}
}
printf("matrix C is \n");
for(i=0;i {
for(j=0;j {
printf("%d\t",c[i][j]);
}
printf("\n");
}
}
getch();
}

2006-10-28 05:18:31 · answer #1 · answered by Innocence Redefined 5 · 1 0

here is logic you have to use...

1. make two 2-dimension array, either input the value from user or do it your self
2. if inputed by user check that number of coloumn of 1st array is equal to row of 2nd array.
3. input the values

4. make two loops. outer loop which will change the row of 1st array and inner loop change the coloumn of the 2nd array..
5. now do element multiplication of row of 1st to coloumn of 2nd and add it and store in new matirx which is result.
6. repeat this to get final answer.

2006-10-28 12:15:17 · answer #2 · answered by here to answer all 2 · 0 0

Here goes...

Matrix Multiplication: M1xM2

Pre condition: Number of columns in M1 should be equal
to number of rows in M2
Algorithm Steps:
1. Read two matrices M1[m][n] and M2[n][r] and initialize another matrix M3[m][r] for storing result.
Repeat for i=0 to m-1
M3[i][j] = 0
Repeat for j=0 to r-1
Repeat for k=0 to n-1
M3[i][j] += M1[i][k] * M2[k][j]
3. Print matrix M3.


C Implementation

#include
#define row1 4
#define col1 3
#define row2 3
#define col2 4
#define row3 4
#define col3 4

void main()
{
int M1[row1][col1],M2[row2][col2],M3[row3][col3];
int i,j,k;

printf(“Enter data for Matrix M1\n”);
for(i=0;i {
for(j=0;j {
scanf(“%d”,&M1[i][j]);
}
printf(“\n”);
}

printf(“Enter data for Matrix M2\n”);
for(i=0;i {
for(j=0;j {
scanf(“%d”,&M2[i][j]);
}
printf(“\n”);
}

if (col1!= row2)
{ printf(“Multiplication is not possible”);
return;
}
for(i=0;i {
for(j=0;j {
M3[i][j] = 0;
for(k=0;k {
M3[i][j] += M1[i][k]*M2[k][j];
}
}
}


printf(“RESULTANT MATRIX IS\n ”);
for(i=0;i {
for(j=0;j {
printf(“%d”,M3[i][j]);
}
printf(“\n”);
}
return;
}

2006-10-28 15:01:47 · answer #3 · answered by Dvidid/0 2 · 1 0

What do you want to know ?

2006-10-28 12:06:20 · answer #4 · answered by Anonymous · 0 1

fedest.com, questions and answers