一、运行结果;
二、源代码;
# define _CRT_SECURE_NO_WARNINGS
# include <stdio.h>
//声明转换函数;
void interchange(int a[3][3], int b[3][3]);
int main()
{
//初始化变量值;
int a[3][3] = { {1, 2, 3}, {4, 5, 6}, {7, 8, 9} };
int b[3][3] = {0};
int k = 0;
int g = 0;
//输出交换前的结果;
printf("数组转换前为:\n");
for (k = 0; k < 3; k++)
{
//列;
for (g = 0; g < 3; g++)
{
//输出;
printf("%d\t", a[k][g]);
}
//换行;
printf("\n");
}
//换行;
printf("\n");
//调用转换函数;
interchange(a, b);
return 0;
}
//实现转换函数;
void interchange(int a[3][3], int b[3][3])
{
//初始化变量值;
int i, j;
//循环交换;
for (i = 0; i < 3; i++)
{
//列;
for (j = 0; j < 3; j++)
{
//交换;
b[j][i] = a[i][j];
}
}
//输出;
printf("数组转换后为:\n");
//循环交换;
for (i = 0; i < 3; i++)
{
//列;
for (j = 0; j < 3; j++)
{
//输出;
printf("%d\t", b[i][j]);
}
//换行;
printf("\n");
}
}