1. Matrix multiplication
Enter two matrices, each of which is the m*s,s*n size. Outputs the result of multiplying the two matrices.
Enter the first line of the format, with a space separated by three positive integer m,s,n (neither more than 200).
The next M line, an integer separated by a space of s per line, represents matrix A (I,J).
Next S line, an integer separated by n spaces per line, represents matrix B (i,j). The output format is M-line, an integer separated by n spaces per line, and the value of Matrix C (i,j) after the output is multiplied. Answer:
#include <stdio.h>
int main (int argc, const char * argv[]) {
Enter M,s,n to determine the size of the rectangle
int m,s,n;
scanf ("%d%d%d", &m,&s,&n);
Input data, determine two matrices
int i,j;
int First[m][s];
int second[s][n];
for (i = 0; i < m; i + +) {
for (j = 0; J < s; ++j) {
scanf ("%d", &first[i][j]);
}
}
for (i = 0; i < s; + + i) {
for (j = 0; J < N; + + j) {
scanf ("%d", &second[i][j]);
}
}
Two multiplication of matrices
int third[m][n];
int z;
int total=0;
for (i = 0; i < m; ++i) {
for (j = 0; J < N; ++j) {
for (total= z = 0; z < s; ++z) {
Total + = First[i][z]*second[z][j];
}
THIRD[I][J] = total;
}
}
Print out the result of multiplying the matrix
for (i = 0; i < m; ++i) {
for (j = 0; J < N; ++j) {
printf ("%d", third[i][j]);
}
printf ("\ n");
}
return 0;
}
2.
Algorithm training of Blue Bridge Cup