7-1 矩陣轉置(10 分)
將一個3×3矩陣轉置(即行和列互換)。
輸入格式:
在一行中輸入9個小於100的整數,其間各以一個空格間隔。
輸出格式:
輸出3行3列的二維數組,每個數據輸出占4列。
輸入樣例:
1 2 3 4 5 6 7 8 9
輸出樣例:
1 4 7
2 5 8
3 6 9
——————————————————————————————————————————————————————————答案稍后————————————————————————————————————————————————————————————
評論區可以寫出你的答案
#include<stdio.h>
#include<iostream>
using namespace std;
int main()
{
int a[3][3];
for(int i=0;i<3;i++)
{
for(int j=0;j<3;j++)
{
cin>>a[i][j];
}
}
for(int i=0;i<3;i++)
{
for(int j=0;j<3;j++)
{
cout<<" "<<a[j][i];
}
cout<<endl;
}
return 0;
}