#include <stdio.h> #include <stdlib.h>char arr[3][3];void print () { int i=0; for (i=0;i<3;i++) { printf ("%c|%c|%c|\n", arr[i][0],arr[i][1],arr[i][2]); printf (" _|_|_|\n "); }}void init_arr () { int i=0; int j=0; for (i=0;i<3;i++) { for (j=0;j<3;j++) { arr[i][j]= ' '; } }}void player () { int i=0; int j=0; printf ("input i,j:\n"); &NBSP;SCANF ("%d %d", &i, &J); i--; j--; if (arr[i][j]!= ' ') { printf ("This grid has been entered, please re-enter i,j:\n"); player (); } else { arr[i][j]= ' X '; }}void computer_move () { int i=0; int j=0; for (i=0;i<3;i++) { for (j=0;j<3;j++) { if (arr[i][j]== ' ') { arr[i][j]= ' 0 '; breAk; } } break; }}char win () { int i=0; for (i=0; i<3;i++) { if ((arr[i][0]==arr[i][1]) && (arr[i][1]==arr[i][2])) { return arr[i][0]; } } for (i=0;i<3;i++) { if (arr[0][i]==arr[1][i) && (Arr[1][i]==arr[2][i]) { return arr[0][i]; } } }int main () { char done; Int i; int j; done= ' '; init_arr (); printf ("board game: \ n"); do { print (); player (); done=win (); if ( done!= ' ') { break; } computer_ Move (); done=win (); }while (done== ' '); if (done== ' 0 ') { printf ("Computer win \ n"); } else { printf ("player wins \ \"); } print (); }
Write five functions, then call 650 with the main function) this.width=650; "title=" Image.png "src=" http://s3.51cto.com/wyfs02/M00/74/AC/ Wkiol1ymawszdfskaah4c_fvhas574.jpg "alt=" wkiol1ymawszdfskaah4c_fvhas574.jpg "/>650" this.width=650; "title=" capture. PNG "src=" http://s3.51cto.com/wyfs02/M02/74/AF/wKiom1YmAz_RlMJlAACDfmGWOfQ747.jpg "alt=" wkiom1ymaz_ Rlmjlaacdfmgwofq747.jpg "/>
"Classic Game Programming Problem" C language: Writing a board game, combined with a two-dimensional array