方阵转置(c++)

#include

#include

 

using namespace std;

 

int main(int argc,char* argv[])

{

    int a[4][4]={

                    {0,1,2,3},

                    {4,5,6,7},

                    {8,9,10,11},

                    {12,13,14,15}

                };

    int tmp;

    cout<<"转置前的矩阵:"<<endl;

    for(int i=0;i<4;i++)

    {

        for(int j=0;j<4;j++)

        {

            cout<<a[i][j]<<" ";

        }

        cout<<endl;

    }

    for(int i=0;i<4;i++)

    {

        for(int j=0;j

        {

            tmp=a[i][j];

            a[i][j]=a[j][i];

            a[j][i]=tmp;

        }

    }

    cout<<"转置后的矩阵:"<<endl;    

    for(int i=0;i<4;i++)

    {

        for(int j=0;j<4;j++)

        {

            cout<<a[i][j]<<" ";

        }

        cout<<endl;

    }

    return 0;

}

运行结果:

 

方阵转置(c++)

posted @ 2016-05-06 18:51  硫酸亚铜  阅读(460)  评论(0编辑  收藏  举报