Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
#include<stdio.h>
#include<conio.h>
char matrix[3][3];
int m,n,i,j,sum,ch;
void cou(void);
void introduction();
void main()
{clrscr();
introduction();
getch();
ch=1;
while(ch==1)
{clrscr();
for (m=0;m<3;m++)
for (n=0;n<3;n++)
matrix[m][n]='\0'; // Initialization of the matrix
sum=0;
while(sum<10)
{if(sum==0)
cou();
printf("Player 1 is 'X': choose the row and column\n\n");
printf("Row : ");
scanf("%d",&i);
printf("\nColumn : ");
scanf("%d",&j);
for(;i>3||i<1||j>3||j<1||('X'==matrix[i-1][j-1])||'O'==matrix[i-1][j-1];)
{printf("Sorry!!!, but you gotta choose another place.\n");
printf ("Row : ");
scanf("%d",&i);
printf("\nColumn : ");
scanf("%d",&j);
}
matrix[i-1][j-1]='X';
sum++;
cou();
break;
}
if (sum==9)
both
stink!!!\n");
break;
}
matrix[0][1]==matrix[0][2])
{printf("\nPlayer 2 wins");
break;
}
if (matrix[1][0]=='O' && matrix[1][0]==matrix[1][1] &&
matrix[1][1]==matrix[1][2])
{printf("\nPlayer 2 wins");
break;
}
if (matrix[2][0]=='O' && matrix[2][0]==matrix[2][1] &&
matrix[2][1]==matrix[2][2])
{printf("\nPlayer 2 wins");
break;
}
}
void cou()
{printf("\n\t\t 1 2 3\n\n");
printf("\t\t1 %c | %c | %c\n", matrix[0][0],matrix[0][1],matrix[0][2]);
printf("\t\t2 %c | %c | %c\n", matrix[1][0],matrix[1][1],matrix[1][2]);
printf("\t\t3 %c | %c | %c\n\n\n", matrix[2][0],matrix[2][1],matrix[2][2]);
}
void introduction()
{clrscr();
printf("\n There is a 3 by 3 array of cells.First you have to choose one cell,
then after that the chance will be given to other player to choose an unmarked
cell.\nA person wins, if he covers any one of th entire row, or entire column
or entire diagonal cells. If one of the players wins, and if all the cells are
covered,then the game is draw.");
}