09: matrix multiplication, 09: Matrix Multiplication

Source: Internet
Author: User

09: matrix multiplication, 09: Matrix Multiplication
09: Matrix Multiplication

  • View
  • Submit
  • Statistics
  • Question
Total time limit:
1000 ms
 
Memory limit:
65536kB
Description

Calculate the multiplication of two matrices. N * m-level matrix A multiplied by m * k-level matrix B. The obtained matrix C is n * k-level, and C [I] [j] = A [I] [0] * B [0] [j] + A [I] [1] * B [1] [j] + ...... + A [I] [M-1] * B [s-1] [j] (C [I] [j] indicates column j of row I in the C matrix ).

Input
The first act is n, m, k, indicating that the matrix is n rows of m columns, the B matrix is m rows of k columns, n, m, k are less than 100
Then, input two matrices, A and B. The A matrix has n rows and m columns, and the B Matrix has m rows and k columns. The absolute values of each element in the matrix are not greater than 1000.
Output
Output matrix C, n rows in total, k integers in each row, separated by a space.
Sample Input
3 2 31 11 11 11 1 11 1 1
Sample output
2 2 22 2 22 2 2

# Include <iostream> using namespace std; int a [1001] [1001]; int B [1001] [1001]; int c [1001] [1001]; int now = 1; // record the I value int tot; // record S-1 int main () {int n, k, m; cin> n> m> k; for (int I = 1; I <= n; I ++) {for (int j = 1; j <= m; j ++) {cin> a [I] [j] ;}} for (int I = 1; I <= m; I ++) {for (int j = 1; j <= k; j ++) {cin> B [I] [j] ;}} for (int I = 1; I <= n; I ++) {for (int j = 1; j <= k; j ++) {while (now <= m) {c [I] [j] = a [I] [now] * B [now] [j] + c [I] [j]; now ++ ;} now = 1 ;}}for (int I = 1; I <= n; I ++) {for (int j = 1; j <= k; j ++) {cout <c [I] [j] <";}cout <endl;} return 0 ;}

 

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.