In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-26 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article will explain in detail how to calculate the product of two matrices in C language. The content of the article is of high quality, so the editor shares it for you as a reference. I hope you will have some understanding of the relevant knowledge after reading this article.
Analysis.
In mathematics, matrix (Matrix) is a set of complex or real numbers arranged according to a rectangular array. Matrix is a common tool in higher algebra, and it is also common in applied mathematics subjects such as statistical analysis.
The multiplication of matrices has the following considerations:
1. When the number of columns of matrix A (column) is equal to the number of rows of matrix B (row), An and B can be multiplied.
2. The number of rows of matrix C is equal to the number of rows of matrix A, and the number of columns of C is equal to the number of columns of B.
3. The element of the m-th row and the nth column of the product C is equal to the sum of the product of the m-th row of the matrix An and the nth column of the matrix B.
Code implementation: only need to use the matrix product formula to find a new matrix, that is, the product of two matrices, the program also needs to determine whether the input of the two matrices can be multiplied.
Code implementation # include int main () {int line_a = 0; / A matrix rows int col_a = 0; / A matrix rows int line_b = 0; / B matrix rows int col_b = 0; / / B matrix columns int I = 0; int j = 0; int k = 0 / * get the number of rows and columns of A matrix * / printf ("Please enter the number of rows and columns of A matrix\ n"); scanf ("% d% d", & line_a, & col_a); int matrix_ A [line _ a] [col_a]; / * get the number of rows and columns of B matrix * / printf ("Please enter the number of rows and columns of B matrix\ n") Scanf ("% d% d", & line_b, & col_b); int matrix_ B [line _ b] [col_b]; if (col_a! = line_b) {printf ("the number of columns of the error,A matrix and the number of rows of the B matrix must be equal! \ n "); return 0;} int matrix_ C [line _ a] [col_b]; / / C matrix: product of A matrix and B matrix / * get A matrix elements * / for (I = 0; I < line_a; iTunes +) {printf (" Please enter% d row elements of A matrix\ n ", I); for (j = 0; j < col_a) Scanf ("% d", & matrix_ A [I] [j]);}} / * get B matrix elements * / for (I = 0; I < line_b; iMatrix +) {printf ("Please enter% d row elements of B matrix\ n", I); for (j = 0; j < col_b) For +) {scanf ("% d", & matrix_ B [I] [j]);}} / * print matrix * / printf ("input A matrix is:\ n"); for (I = 0; I < line_a; iTunes +) {for (j = 0; j < col_a) Printf +) {printf ("% d\ t", matrix_ A [I] [j]);} printf ("\ n");} printf ("input B matrix is:\ n"); for (I = 0; I < line_b; iMatrix +) {for (j = 0; j < col_b) Printf +) {printf ("% d\ t", matrix_ B [I] [j]);} printf ("\ n");} / * find the product of AB, that is, matrix C * / for (I = 0; I < line_a; iTunes +) {for (j = 0; j < col_b; jacks +) {matrix_ C [I] [j] = 0 / initialize for (k = 0; k < col_a; knot +) matrix_ C [I] [j] + = matrix_ A [I] [k] * matrix_ B [k] [j];}} / * print C matrix * / printf ("A matrix multiplied B matrix:\ n"); for (I = 0; I < line_a; iMatrix +) {for (j = 0) J < col_b; jacks +) {printf ("% d\ t", matrix_ C [I] [j]);} printf ("\ n");} return 0;}
Running result
About C language how to find the product of two matrices is shared here, I hope the above content can be of some help to you, can learn more knowledge. If you think the article is good, you can share it for more people to see.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.