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">/*
- 5、 写一函数,将一个3×3的矩阵转置。
- */
- #include <stdio.h>
- #include <stdlib.h>
-
- void main()
- {
- int a[3][3];
- int b[3][3];
- for (int i=0;i<3;i++)//给数组赋值
- {
- for (int j=0;j<3;j++)
- {
- a[j]=rand()%100;
- printf("%d\t",a[j]);
- }
- printf("\n");
- }
-
- printf("\n");
- for (int i=0;i<3;i++)//转置矩阵
- {
- for (int j=i+1;j<3;j++)
- {
- int temp;
- temp=a[j];
- a[j]=a[j];
- a[j]=temp;
- }
- }
-
- for (int i=0;i<3;i++)//重新输出
- {
- for (int j=0;j<3;j++)
- {
- printf("%d\t",a[j]);
- }
- printf("\n");
- }
- system("pause");
- }</pre><br><br></pre></pre>
|
|