#include #include #include int main(){ srand(time(NULL)); int i,j,numa,numb,numc; char board[9][9],num[9]; memset(board,0,sizeof(board)); memset(num,0,sizeof(num)); int randchar(char* c){ int i,j,temp,numa,numb; for(j=0;j<9;j++){ c[j]=j+1; } for(i=0;i<50;i++){ numa=rand()%9; do{ numb=rand()%9; }while(numb==numa); temp=c[numa]; c[numa]=c[numb]; c[numb]=temp; } //return c; } for(i=0;i<3;i++){ randchar(num); for(j=0;j<3;j++){ numa=rand()%9; do{ numb=rand()%9; }while(numb==numa); do{ numc=rand()%9; }while(numc==numa&&numc==numb); board[j+3*i][numa]=num[0+3*j]; board[j+3*i][numb]=num[1+3*j]; board[j+3*i][numc]=num[2+3*j]; } } for(i=0;i<9;i++){ if(i==0||i==3||i==6){ printf("|-----------------------|\n"); } printf("| "); for(j=0;j<9;j++){ if(board[i][j]!=0){ printf("%d ",board[i][j]); } else{ printf(". "); } if(j==2||j==5||j==8){ printf("| "); } if(j==8){ printf("\n"); } } } printf("|-----------------------|\n"); }