如題
#include <stdio.h>
#define ROW 3
#define COL 4//使用宏定義行和列
void Transpose(int *a, int *at, int row, int col);//轉置
void InputMatrix(int *s, int row, int col);//輸入
void PrintMatrix(int *s, int row, int col);//輸出
int main(void)
{
int s[ROW][COL]; //s代表原矩陣
int st[COL][ROW]; //st代表轉置後的矩陣
printf("Please enter matrix:\n");
//輸入原矩陣,*s指向矩陣s的0行0列,是列指針
/***************Begin**************/
//此處應有函數調用
InputMatrix(*s,ROW,COL);
/***************End***************/
//對矩陣s進行轉置,結果存放於st中
/***************Begin**************/
//此處應有函數調用
Transpose(*s, *st, ROW, COL);
/***************End***************/
printf("The transposed matrix is:\n");
//輸出轉置矩陣,*st指向st的0行0列,是列指針
/***************Begin**************/
//此處應有函數調用
PrintMatrix(*st, COL,ROW);
/***************End***************/
return 0;
}
//函數功能: 對任意row行col列的矩陣a轉置,轉置後的矩陣爲at
void Transpose(int *a, int *at, int row, int col)
{
/***************Begin**************/
int i,j;
for(i=0;i<row;i++)
for(j=0;j<col;j++)
{
*(at+j*row+i)=*(a+i*col+j);
}
/***************End***************/
}
void InputMatrix(int *s, int row, int col) //輸入矩陣元素
{
int i, j;
for (i=0; i<row; i++)
{
for (j=0; j<col; j++)
{
scanf("%d", s+i*col+j); //這裏s+i*col+j等價於&s[i][j]
}
}
}
void PrintMatrix(int *s, int row, int col) //輸入矩陣元素
{
int i, j;
for (i=0; i<row; i++)
{
for (j=0; j<col; j++)
{
printf("%d\t",*(s+i*col+j));//這裏*(s+i*col+j)等價於s[i][j]
}
printf(" \n");
}
}