# [Linear algebra] multiplication of Matrices

Source: Internet
Author: User
`[Linear algebra] multiplication of Matrices `
` 1   //  Matrix Multiplication    2 # Include <iostream> 3   Using   Namespace STD; 4    5   6   Int Main () 7 {8       Int Am,; 9       Int BM, Bn; 10       Int A [ 100 ] [ 100 ]; //  Matrix    11       Int B [ 100 ] [ 100 ];//  Matrix B    12       Int C [ 100 ] [ 100 ] = { 0 }; //  Matrix C result matrix    13 Cout < "  Enter the number of rows and columns of matrix.  " ;14 Cin> am>; 15 Cout < "  Enter the number of rows and columns of matrix B.  " ; 16 Cin> BM> Bn; 17       If (! = BM) //  If the number of columns in matrix A must be different from that in matrix B, multiplication cannot be performed.    18 Cout < " The two matrices cannot be used for multiplication!  " ; 19       Else  20 { //  The number of columns in matrix A must be equal to the number of rows in matrix B before multiplication.    21 Cout < "  Enter matrix  " <Endl; 22           For (Int I = 0 ; I <am; I ++) 23               For ( Int J = 0 ; J <an; j ++) 24 { 25 Cin> A [I] [J]; 26 } 27 Cout < "  Enter matrix B " <Endl; 28           For ( Int I = 0 ; I <bm; I ++) 29               For ( Int J = 0 ; J <Bn; j ++) 30 { 31 Cin> B [I] [J]; 32 } 33           //  The following is a matrix multiplication calculation.  34   //  The number of rows and columns in the result matrix is determined by matrix AB. The result matrix is C am * bn.    35           For ( Int I = 0 ; I <am; I ++) 36               For ( Int J = 0 ; J <Bn; j ++) 37 { 38                   For ( Int II = 0 ; II <an; II ++) 39 { 40 C [I] [J] + = A [I] [II] * B [II] [J]; 41 } 42 } 43 Cout < " The result of matrix A * matrix B is:  " <Endl; 44           For ( Int I = 0 ; I <am; I ++) 45 { 46               For ( Int J = 0 ; J <Bn; j ++) 47 { 48 Cout <C [I] [J] < "  " ; 49 } 50 Cout <Endl; 51 } 52 } 53 System ( "  Pause  " ); 54       Return  0 ; 55 }`
`  `
Related Keywords:

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.