收藏 分享(赏)

C语言编程学习课件 (33).pdf

上传人:职教中国 文档编号:13894313 上传时间:2022-11-06 格式:PDF 页数:10 大小:1.89MB
下载 相关 举报
C语言编程学习课件 (33).pdf_第1页
第1页 / 共10页
C语言编程学习课件 (33).pdf_第2页
第2页 / 共10页
C语言编程学习课件 (33).pdf_第3页
第3页 / 共10页
亲,该文档总共10页,到这儿已超出免费预览范围,如果喜欢就下载吧!
资源描述

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

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 高等教育 > 大学课件

本站链接:文库   一言   我酷   合作


客服QQ:2549714901微博号:道客多多官方知乎号:道客多多

经营许可证编号: 粤ICP备2021046453号世界地图

道客多多©版权所有2020-2025营业执照举报