編寫一個函數(shù)(參數(shù)用指針)將一個3行3列的二維數(shù)組a轉(zhuǎn)置后保存到一個二維數(shù)組b, 即將任意一個元素b[row][col]賦值為a[col][row]。轉(zhuǎn)置的舉例:1 2 3 轉(zhuǎn)置后變成: 1 4 74 5 6 2 5 87 8 9 3 6 9
1 回答

慕田峪7331174
TA貢獻1828條經(jīng)驗 獲得超13個贊
//#include "stdafx.h"//vc++6.0加上這一行.
#include "stdio.h"
void myprint(int (*p)[3]){
int i,j;
for(i=0;i<3;i++){
for(j=0;j<3;printf("%3d",p[i][j++]));
printf("\n");
}
}
void mytranspose(int (*p)[3],int (*q)[3]){
int i,j;
for(i=0;i<3;i++)
for(j=0;j<3;q[j][i]=p[i][j++]);
}
int main(void){
int a[3][3]={{1,2,3},{4,5,6},{7,8,9}},b[3][3];
printf("Before the transpose:\n");
myprint(a);
printf("After the transpose:\n");
mytranspose(a,b);
myprint(b);
return 0;
}
- 1 回答
- 0 關(guān)注
- 1563 瀏覽
添加回答
舉報
0/150
提交
取消