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

multiply two matrices of order n *m and m *o respectively to produce a resultant matirx of order n *o

2007-01-28 23:54:31 · 2 answers · asked by SSS 3 in Computers & Internet Programming & Design

or in C++ language

2007-01-29 00:05:13 · update #1

2 answers

#include
#include
#include

int main() {
int i,j,sum;
int a[20][20]={{0}};
int b[20][20]={{0}};
int c[20][20]={{0}};

int m=2, n=3, o=4,k=0;


printf("\n\nThe created first matrix m x n \n");
for(i=0;i for(j=0;j a[i][j]=1+rand()%10;
printf("%4d",a[i][j]);
}
printf("\n\n");
}


printf("\n\nThe created second matrix n x o\n");
for(i=0;i for(j=0;j b[i][j]=1+rand()%10;
printf("%4d",b[i][j]);
}
printf("\n\n");
}
printf("\n\n");
printf("\n\nThe product matrix m x o\n");
for(i=0;i for(k=0;k for(j=0;j c[i][k]= c[i][k]+ a[i][j]* b[j][k];
}
printf("%4d",c[i][k]);
}
printf("\n\n");

}
printf("\n\n");
getchar();
}

2007-01-29 00:05:51 · answer #1 · answered by iyiogrenci 6 · 0 0

Matrix multiplication is a lot more complex then just a nested for loop. A simple double-loop would only do element-by-element array multiplication, which is not matrix multiplication.

See here for a basic method: http://www.phanderson.com/C/mat_mult.html

2007-01-29 11:09:33 · answer #2 · answered by Dr.Mr.Ed 5 · 0 0

fedest.com, questions and answers