#include<iostream>#include<stdio.h>
using namespace std;voidprintM(int M){//只有一個數的時候輸出1if(M ==1){printf("1");}//生成在拉丁方陣中出現的數據序列int*elementArray = new int[M];for(int i =0; i < M; i++){
elementArray[i]= i +1;}//動態生成一個二維數組int**shouList = new int*[M];//開闢行for(int i =0; i < M; i++)
shouList[i]= new int[M];//開闢列for(int i =0; i < M; i++){//寫入一行方陣for(int k =0; k < M; k++){
shouList[i][k]= elementArray[k];}//將數據序列循環左移一位int temp;
temp = elementArray[0];for(int i =0; i < M -1; i++){
elementArray[i]= elementArray[i+1];}
elementArray[M -1]= temp;}//打印方陣for(int i =0; i < M; i++){for(int j =0; j < M; j++){printf("%2d", shouList[i][j]);}printf("\n");}};intmain(){int M =0;printf("Please input M :");scanf_s("%d",&M);printM(M);system("pause");return0;}