三阶行列式转置

#include<iostream>
using namespace std;
int main()
{
    int t;
    int a[3][3]={ {1,2,3},{4,5,6},{7,8,9}};
    for(int i=0;i<3;i++)
    {
        for(int j=0;j<i;j++)//这句中的j<i是关键
        {
            if(i!=j)
            {
                t=a[i][j];
                a[i][j]=a[j][i];
                a[j][i]=t;
            }
        }
    }
    for(i=0;i<3;i++)
        for(int j=0;j<3;j++)
        {
            cout<<a[i][j];
            if(j==2)
                cout<<endl;
        }

    return 0;
}

猜你喜欢

转载自blog.csdn.net/m0_47575628/article/details/108944277