#include<stdio.h> int a[100][100]={{1,1,1,1,1,1},{1,0,1,0,1,1},{1,0,1,0,1,1},{1,0,0,0,0,1},{1,1,0,1,0,1},{1,1,1,1,1,1}},n=6,b=0; void migng(int x,int y) { int i,j; a[x][y]=2; if(x==n-2&&y==n-2) { for(i=0;i<=n-1;i++) { for(j=0;j<=n-1;i++) { printf("%d",a[i][j]); } printf("\n"); } printf("\n"); b++; } else { if(a[x+1][y]==0) migng(x+1,y); if(a[x][y+1]==0) migng(x,y+1); if(a[x-1][y]==0) migng(x-1,y); if(a[x][y-1]==0) migng(x,j-1); a[x][j]==2; } } int main() { int x=1,y=1,i,j; // for(i=0;i<=n-1;i++) // for(j=0;j<=n-1;j++) // scanf("%d",&a[i][j]); migng(x,y); if(b==0) printf("no"); return 0; }
怎么改?
#include<stdio.h> int a[7][7]={{1,1,1,1,1,1,1}, {1,0,0,1,0,1,1}, {1,1,0,0,0,1,1}, {1,0,0,0,1,1,1}, {1,1,1,0,0,0,1}, {1,0,1,0,0,0,1}, {1,1,1,1,1,1,1}},t=0; int f(int i,int j) { a[i][j]=2; if(i==5&&j==5) { for(i=0;i<=6;i++) { for(j=0;j<=6;j++) printf("%d",a[i][j]); printf("\n"); } printf("\n"); t++; } else { if(a[i][j+1]==0) f(i,j+1); if(a[i+1][j]==0) f(i+1,j); if(a[i][j-1]==0) f(i,j-1); if(a[i-1][j]==0) f(i-1,j); a[i][j]=0; } } int main() { int b=1,c=1; f(b,c); if(t==0) printf("%d",t); return 0; }