Matrix Multiplication, matrix multiplication Formula

Source: Internet
Author: User

Matrix Multiplication, matrix multiplication Formula

 

1 # include <stdio. h> 2 3 // macro definition 4 # define max_row 200 // defines the maximum number of rows in the Matrix 5 # define max_column 200 // defines the maximum number of columns in the Matrix 6 7 int main () 8 {9 int I, j, k; 10 int m, s, n; // records the number of rows and columns of the matrix A, B, and C: matrix A: m * s; matrix B: s * n; matrix C: m * n 11 int A [max_row] [max_column], B [max_row] [max_column], C [max_row] [max_column] ={{ 0}, {0 }}; // three two-dimensional arrays, record matrices A, B, and C 12 13 // enter 14 scanf ("% d", & m, & s, & n ); // input row and column 15 for (I = 0; I <m; I ++) // input matrix A 16 for (j = 0; j <s; j ++) 17 scanf ("% d", & A [I] [j]); 18 for (I = 0; I <s; I ++) // input matrix B 19 for (j = 0; j <n; j ++) 20 scanf ("% d", & B [I] [j]); 21 22 // multiply the matrix by 23 for (I = 0; I <m; I ++) 24 for (j = 0; j <n; j ++) 25 for (k = 0; k <s; k ++) 26 C [I] [j] + = A [I] [k] * B [k] [j]; // matrix C should be m row n column, where C (I, j) is equal to the Inner Product 27 28 of the row vector of matrix A and the vector of column j of matrix B // output 29 for (I = 0; I <m; I ++) 30 {31 for (j = 0; j <n; j ++) 32 printf ("% d", C [I] [j]); 33 putchar ('\ n'); 34} 35 36 return 0; 37}

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.