Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<stdio.h>
- int main()
- {
- int i,x,y,z,count=0,n1,n2,p1=0,p2=0;
- char st[9]={'1','2','3','4','5','6','7','8','9'};
- again:
- for(i=0,x=0,y=1,z=2;i<3;i++,x+=3,y+=3,z+=3)
- {
- printf("\t %c | %c | %c\n",st[x],st[y],st[z]);
- if(i==0||i==1)
- {
- for(int j=0;j<1;j++)
- {
- printf("\t-----------\n");
- }
- }
- }
- if((st[0]==st[1]&&st[1]==st[2])||(st[0]==st[3]&&st[3]==st[6])||(st[6]==st[7]&&st[7]==st[8])||(st[2]==st[5]&&st[5]==st[8])||(st[0]==st[4]&&st[4]==st[8])||(st[2]==st[4]&&st[4]==st[6]))
- {
- if(p1>p2)
- printf("\n Player 1 Wins\n");
- else
- printf("\n Player 2 Wins\n");
- }
- else if(count==9)
- {
- printf("\nMath Draw\n");
- }
- else
- {
- if(p1==p2)
- {
- again1:
- printf("\nPlayer 1 ( X ) = ");
- scanf("%d",&n1);
- printf("\n");
- if(st[n1-1]=='X'||st[n1-1]=='O')
- {
- printf("Already Occupied!!\n\tTry Again..\n");
- goto again1;
- }
- st[n1-1]='X';
- p1++;
- count++;
- }
- else
- {
- again2:
- printf("\nPlayer 2 ( O ) = ");
- scanf("%d",&n2);
- printf("\n");
- if(st[n2-1]=='X'||st[n2-1]=='O')
- {
- printf("Already Occupied!!\n\tTry Again..\n");
- goto again2;
- }
- st[n2-1]='O';
- p2++;
- count++;
- }
- goto again;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement