1、Programming In C Transpose of A Matrix what is matrix transposition? Swap the rows and columns of matrix A, and the new matrix is the transposed matrix of A. transpose Programming Supposing we have defined a two-dimensional array of integers a53 and stored the data into matrix A. int a53= 5, 21, 17,
2、 23, 10, 9, 7, 15, 4, 18, 2, 31, 6, 20, 5 ; Then, we define another two-dimensional array of integers b35 to store the transposed matrix of A. int b35; Programming According to the concept of matrix transposition. We need to convert the rows to columns in array a, and store them in array b. transpos
3、e b00 a00 assign to b10 a01 assign to b20 a02 assign to Programming for(i=0;i5;i+) for(j=0;j3;j+) bji=aij; When i=0, j=0, b00 gets value of a00; j=1, b10 gets value of a01; j=2, b20 gets value of a02. Continue the loop until the transposition of matrix A is completed. Code Running result 5 23 7 18 6
4、 21 10 15 2 20 17 9 4 31 5 Second Application Input an N-order square matrix, output it and output the sum of the elements on its leading diagonal. For example, 4-order square matrix. The leading diagonal refers to such a line drawn from the upper left corner to the lower right corner. For elements
5、on the leading diagonal, the subscripts of rows and columns are the same. Programming for(i=0;iN;i+) sum=sum+aii; Based on the characteristics that the diagonal elements have the same row and column subscripts, we can use a statement “sum=sum+aii;” in loop body. Code We use a double nested loop to input the data of the N-order square matrix. We also use a double nested loop to output the data of the N-order square matrix. calculate the sum of the elements on the diagonal. First, we use macro definition to define symbolic constant N. Running result Programming In C