不使用[]C语言将值扫描到矩阵中

不使用[]C语言将值扫描到矩阵中,c,matrix,transpose,C,Matrix,Transpose,我有个问题。我被要求编写一个程序来转置矩阵,而不使用[]……例如,我知道如果它是一维数组,我可以说数组[3]与*(数组+3)相同……但如何使用矩阵来实现这一点 这是我的扫描代码: void scan_matrix(matrix mat1,int number_of_rows, int number_of_columns) { int row_index,column_index; for(row_index=0;row_index<number_of_rows;row_in

我有个问题。我被要求编写一个程序来转置矩阵,而不使用[]……例如,我知道如果它是一维数组,我可以说数组[3]与*(数组+3)相同……但如何使用矩阵来实现这一点

这是我的扫描代码:

void scan_matrix(matrix mat1,int number_of_rows, int number_of_columns)
{
    int row_index,column_index;
    for(row_index=0;row_index<number_of_rows;row_index++)
    {
        printf("Enter the values of row %d\n",row_index);
        for(column_index=0;column_index<number_of_columns;column_index++)
            scanf("%d",WHAT GOES HERE?????);
    }
}
void scan\u矩阵(矩阵mat1,行的整数,列的整数)
{
int行索引,列索引;

对于(row_index=0;row_index如果
mat1
是一个简单的指针,那么这将为您完成以下工作:

for(row_index=0;row_index<number_of_rows;row_index++)
    {
        printf("Enter the values of row %d\n",row_index);
        for(column_index=0;column_index<number_of_columns;column_index++)
            scanf("%d", (mat1 + row_index*number_of_columns + column_index));
    }
它存储在内存中的形式为:

1 2 3 4 5 6
因此,通过将数组元素的逻辑位置映射到实际位置的方法来访问正确的变量。我们所需要的只是找出以下关系:

Pos = Row*Num_Of_Col + Col

如果mat是二维int数组,如:mat[3][3]

然后scanf代码将是:
scanf(“%d”)(*(mat+行索引)+列索引));


这取决于
矩阵是什么,
是一个二维数组。有行和列。我对这一点不熟悉,如果问题不清楚,很抱歉。@OriaGruber如果您不愿意使用[],那么您必须使用*算术
Pos = Row*Num_Of_Col + Col
a[3] : *(a+3)
a[3][3] : (*(a+3)+3)