Algorithm training of Blue Bridge Cup

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.