#include <stdio.h> #define N 6 /*确定N值*/ int main1() { int i, j, k, t; printf( "The possble Latin Squares of order %d are:\n", N ); for ( j = 0; j < N; j++ ) /*构造N个不同的拉丁方阵*/ { for ( i = 0; i < N; i++ ) { t = (i + j) % N; /*确定该拉丁方阵第i 行的第一个元素的值*/ for ( k = 0; k < N; k++ ) /*按照环的形式输出该行中的各个元素*/ printf( "%d", (k + t) % N + 1 ); printf( "\n" ); } printf( "\n" ); } } int main2() { int a[2 * N]; int b[N][N]; int i, j, k = 0; a[0] = 2; /* for( i=0;i<2*N;i++) a[i]=i%N+1; */ for ( i = 0; i < 2 * N; i++ ) { a[i] = i % 7 + 2; if ( a[i] > N ) a[i] %= N; } for ( i = 0; i < N; i++ ) { k = i; for ( j = 0; j < N; j++ ) { b[i][j] = a[k++]; } } for ( i = 0; i < N; i++ ) { for ( j = 0; j < N; j++ ) { printf( " %d ", b[i][j] ); } printf( "\n" ); } return(0); } int main() { int b[N][N]; int i, j, k = 0; for ( i = 5; i >= 0; i-- ) { for ( j = 0; j < N; j++ ) { b[j][i] = (i + j + 7) % 6 + 1; } } for ( i = 5; i >= 0; i-- ) { for ( j = 0; j < N; j++ ) { b[j][i] = (i + j + 5) % 6 + 1; } } for ( i = 0; i < N; i++ ) { for ( j = 0; j < N; j++ ) { printf( " %d ", b[i][j] ); } printf( "\n" ); } return(0); }
时间: 2024-10-09 23:47:22