TA的每日心情 | 开心 2014-6-18 08:29 |
---|
签到天数: 14 天 [LV.3]偶尔看看II
滴水大师
 
- 积分
- 2345
|
题目
解决代码及点评
- <pre code_snippet_id="91880" snippet_file_name="blog_20131202_1_2646179" class="cpp" name="code"></pre><pre code_snippet_id="91880" snippet_file_name="blog_20131202_1_2646179" class="cpp" name="code"><pre code_snippet_id="91880" snippet_file_name="blog_20131202_1_2646179" class="cpp" name="code"><pre code_snippet_id="91880" snippet_file_name="blog_20131202_1_2646179" class="cpp" name="code">/************************************************************************/
- /*
- 4. 写一函数,使给定的一个二维数组(3×3)转置,即行列互换。
-
- */
- /************************************************************************/
- #include <stdio.h>
- #include <stdlib.h>
- #include <math.h>
- #include <string.h>
-
- // 转置就是a[j]和a[j]交换即可
- void main()
- {
- int arr[3][3]={0};
- for (int i=0;i<3;i++) // 初始化矩阵
- {
- for (int j=0;j<3;j++)
- {
- arr[j]=rand()%100;
- }
- }
- for (int i=0;i<3;i++) // 打印矩阵
- {
- for (int j=0;j<3;j++)
- {
- printf("%5d",arr[j]);
- }
- printf("\n");
- }
- for (int i=0;i<3;i++) // 转置矩阵,就是让a与a[j]交换
- {
- for (int j=i+1;j<3;j++)
- {
- int temp=arr[j];
- arr[j]=arr[j];
- arr[j]=temp;
- }
-
- }
- printf("\n");printf("\n");printf("\n");
- for (int i=0;i<3;i++) // 打印转置后的结果
- {
- for (int j=0;j<3;j++)
- {
- printf("%5d",arr[j]);
- }
- printf("\n");
- }
- system("pause");
- }</pre><br><br></pre></pre>
|
|