看板 NTUBIME101HW 關於我們 聯絡資訊
#include <iostream> using namespace std; int A[100][100],B[100][100]; int M,N; void change(); int main() { cout<<"請輸入MN"; cin>>M>>N; for(int i=0;i<M;i++) { cout<<"請輸入"<<i+1<<"列的"<<N<<"個元素"; for(int j=0;j<N;j++) cin>>A[i][j]; } cout<<"輸入的矩陣"<<endl;; for(int i=0;i<M;i++) { for(int j=0;j<N;j++) cout <<"\t"<< A[i][j]; cout <<endl; } change(); cout<<"轉置矩陣"<<endl; for(int i=0;i<N;i++) { for(int j=0;j<M;j++) cout <<"\t"<< B[i][j]; cout <<endl; } system("pause"); } void change() { for(int i=0;i<M;i++) for(int j=0;j<N;j++) B[j][i]=A[i][j]; } ----------------------------------------------- 不知道有沒有比較簡單@@? 快考試了 在版上的看看吧! -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 140.112.241.88