您的位置:首页 > 其它

写一个函数,使给定的一个二维数组(NXM)转置,即行列互换

2014-05-18 16:28 656 查看
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#include<string.h>
#include<Windows.h>

#define N 3
#define M 3
void rankexchange(int a1
[M])
{
int b1
[M];
for (int i = 0; i < N;i++)
for (int j = 0; j < M; j++)
{
b1[j][i] = a1[i][j];
}
for (int i = 0; i < N; i++)
for (int j = 0; j < M; j++)
{
a1[i][j] = b1[i][j];
}

}
void main()
{
int a
[M] = {
{ 1, 2, 3 },
{ 1, 2, 3 },
{ 1, 2, 3 }
};
rankexchange(a);
for (int i = 0; i < N; i++)//打印结果
{
for (int j = 0; j < M; j++)
{
printf("%3d", a[i][j]);
}
printf("\n");
}
system("pause");
}

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐