题目如下;
填表格 将1、2、3、4、5和6填入2行3列的表中,要使得每一个列右边的数字比左边的数字大,每一行下面的数字比上面的数字大。按此要求,可有几种填写方法? **输出提示信息:"The possible table satisfied above conditions are:n" **输出格式要求:"nNo.:%d" "n%3d" "%3d"
代码如下:
#includeint main() { int a[6],count=0; a[0]=1; a[5]=6; printf("The possible table satisfied above conditions are:n"); for(int i=2;i<=5;i++) { for(int j=2;j<=5;j++) { for(int k=2;k<=5;k++) { for(int l=2;l<=5;l++) { a[1]=i; a[2]=j; a[3]=k; a[4]=l; if(a[1]a[3]&&a[2]>a[1]&&a[1]!=a[4]&&a[2]!=a[1]&&a[4]!=a[3]&&a[1]!=a[3]&&a[2]!=a[3]&&a[2]!=a[4]) { count++; printf("nNo.:%d",count); printf("n%3d",a[0]); for(int n=1;n<6;n++) { printf("%3d",a[n]); if(n==2) { printf("n"); } } } } } } } return 0; }
欢迎交流。



