C數組實現矩陣的轉置

來源:互聯網
上載者:User

標籤:c   執行個體   矩陣轉置   數組   

直接上代碼,在代碼中有對矩陣的學習,包括初始化學習以及如何使用等。

#include <stdio.h>/** * 給出提示,要求輸入數組A * ,通過二維數組,進行數組的轉置 * 得出數組B,輸出結果 * * 該執行個體主要是為了進行學習二維數組 * @brief main * @return */int main(void){    /**     * 二維數組的初始化:     * 1:分行給二維數組賦值     *  static int a[3][4] = {{1,2,3,4},{5,6,7,8},{9,10,11,12}};     *     * 2:將所有資料寫在一個大括弧中     * static int a[3][4] = {1,2,3,4,5,6,7,8,9,10,11,12};     *     * 3:對數組進行部分賦值     * static int a[3][4] = {{1},{2},{3}};     * 相當於該數組為     *  1 0 0 0     *  2 0 0 0     *  3 0 0 0     */    //下面進行執行個體編寫    int row,colume;    printf("Please the number of row and colume of the array(divided by ‘,‘):\n");    scanf("%d,%d",&row,&colume);  //擷取輸入的行數和列數    //定義數組A    int array[row][colume];    int i,j;    //擷取使用者的輸入來填充數組A    for(i = 0;i < row;i++){        for(j = 0;j < colume;j++){            printf("Please enter the number in (%d,%d):\n",i,j);            scanf("%d",&array[i][j]);        }    }    //定義數組B    int MatrixB[colume][row];    //進行轉置    /**     *  兩個數組如果相互轉置的話,     *  則一個數組的行等於另一個數組的列     *  一個數組的列等於另一個數組的行     *  注意:     *  轉置之後的矩陣的行數和列數為轉置之前的列數和行數     */    for(i = 0;i < colume;i++){        for(j = 0;j < row;j++){            MatrixB[i][j] = array[j][i];        }    }    //輸出矩陣B    for(i = 0;i < colume;i++){        for(j = 0;j < row;j++){            printf("%d\t",MatrixB[i][j]);        }        printf("\n");    }    return 0;}

C數組實現矩陣的轉置

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.