使用行列互換的迴圈寫法,須注意輸出的格式。
程式碼:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
using namespace std; | |
int main() | |
{ | |
const int SIZE = 100; | |
int matrix[SIZE][SIZE]; | |
int row, col; | |
while(cin >> row >> col) | |
{ | |
for(int i = 0; i < row; i++) | |
{ | |
for(int j = 0; j < col; j++) | |
{ | |
cin >> matrix[i][j]; | |
} | |
} | |
for(int j = 0; j < col; j++) | |
{ | |
for(int i = 0; i < row - 1; i++) | |
{ | |
cout << matrix[i][j] << " "; | |
} | |
cout << matrix[row-1][j]; | |
cout << endl; | |
} | |
} | |
return 0; | |
} |
沒有留言:
張貼留言