码迷,mamicode.com
首页 > 其他好文 > 详细

第18题 编写程序,实现矩阵(3行3列)的转置(即行列互换)。

时间:2015-04-25 10:42:08      阅读:234      评论:0      收藏:0      [点我收藏+]

标签:

 1 #include<stdio.h>
 2 void P(int a[][3])        //【warning】二维数组必须给出列的具体数据
 3 {
 4     for(int i=0 ; i<3 ; ++i)
 5     {
 6         for(int j=0 ; j<3 ;++j)
 7             printf("%d ",a[i][j]);
 8         printf("\n");
 9     }
10 }
11 int main(int argc , char* argv[])
12 {
13     int arr[3][3]={ 1,2,4,
14                     3,5,7,
15                     9,0,6 };
16     printf("原始:\n");
17     P(arr);
18     for(int i=0 ; i<3 ; ++i)
19         for(int j=i ; j<3 ; ++j)
20         {
21             int tmp=arr[i][j];
22             arr[i][j]=arr[j][i];
23             arr[j][i]=tmp;
24         }
25     printf("转置:\n");
26     P(arr);
27     return 0;
28 }

涉及到二维数组传参数的方法

第18题 编写程序,实现矩阵(3行3列)的转置(即行列互换)。

标签:

原文地址:http://www.cnblogs.com/Evence/p/4455422.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!