Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save Charan1010/d498eadc894d1a7a8970 to your computer and use it in GitHub Desktop.
Save Charan1010/d498eadc894d1a7a8970 to your computer and use it in GitHub Desktop.
#include<stdio.h>
#include<string.h>
main()
{
int a[3][3],m,i,j,k=1,r=0,b=1;
char x[20],y[20];
printf(" WELCOME TO TICTACTOE\n\n");
printf("Enter the name of first player\n\n");
scanf(" %s",x);
printf("\n\nEnter the name of second player\n\n");
scanf(" %s",y);
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
a[i][j]=k;
k++;
}
}
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
printf(" %d",a[i][j]);
}
printf("\n\n\n");
}
printf(" >>The above matrix represents the positions of game<<\n");
printf(" >>Inputs at the positons must be either 0 or 9<<\n");
while(b!=0)
{
r++;
if(r%2==0)
{
printf(" >>plz enter the position Mr:%s<<\n",y);
}
else{
printf(" >>plz enter the position Mr:%s<<\n",x);
}
scanf("%d",&m);
switch(m)
{
case 1:
scanf("%d",&a[0][0]);
break;
case 2:
scanf("%d",&a[0][1]);
break;
case 3:
scanf("%d",&a[0][2]);
break;
case 4:
scanf("%d",&a[1][0]);
break;
case 5:
scanf("%d",&a[1][1]);
break;
case 6:
scanf("%d",&a[1][2]);
break;
case 7:
scanf("%d",&a[2][0]);
break;
case 8:
scanf("%d",&a[2][1]);
break;
case 9:
scanf("%d",&a[2][2]);
break;
default:
printf("plz enter the mentioned position\n");
}
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
printf(" %d",a[i][j]);
}
printf("\n\n\n");
}
if((a[0][0]==a[1][1]&&a[1][1]==a[2][2])||(a[0][2]==a[1][1]&&a[1][1]==a[2][0])||(a[0][0]==a[0][1]&&a[0][1]==a[0][2])||(a[1][0]==a[1][1]&&a[1][1]==a[1][2])||(a[2][0]==a[2][1]&&a[2][1]==a[2][2])||(a[0][0]==a[1][0]&&a[1][0]==a[2][0])||(a[0][1]==a[1][1]&&a[1][1]==a[2][1])||(a[0][2]==a[1][2]&&a[1][2]==a[2][2]))
{
printf(" >>GAME OVER<<\n\n");
b=0;
}
}
if(r%2==0)
{
printf(" WINNER IS Mr:%s\n\n",y);
printf(" CONGRATULATIONS %s",y);
}
else
{
printf(" WINNER IS Mr:%s\n",x);
printf(" CONGRATULATIONS %s",x);
}
}
@Charan1010
Copy link
Author

is my code good or not.plz comment.im a basic programmer who knows only c .and it is my trial

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment