NotesWhat is notes.io?

Notes brand slogan

Notes - notes.io

/* | |* 00 03 06
__|__|__ 20 23 26
| |X 40 43 46
__|__|__
| |
| | */
#include<stdio.h>
#include<stdlib.h>
#include<time.h>
char a[6][8]={' '};
int flag;
void display();
void welcome_design();
int data(int x);
int check(int c,int d);
int logic(int f);
void main()
{
int choice,com,i=0;
welcome_design();
do{
flag=1; // flag 1 represent the user
printf("Enter your choice:(1-9)");
scanf("%d",&choice);
data(choice); // putting data of user in the design
if(i>1){
if(logic(flag)){
display();
printf("nntt______________________________________________________________n");
printf("nntt*****tCONGRATULATION. YOU WIN THE GAME.t*****n");
exit(0);
}
}
if(i==4){
goto last; // After completion of all try terminating the loop
}
flag=2; // flag 2 represent the computer
srand(time(0));
com=rand()%10;
data(com); // putting data of computer in the design
display(); // Displaying the recently entered datas
if(i>1){
if(logic(flag)){
printf("nntt______________________________________________________________n");
printf("nntt*****tTRY AGAIN. COMPUTER WON THE GAME.t*****n");
exit(0);
}
}
i++;
}while(i<5);
last:
display();
printf("ntThe game is draw.");
}
void display(){
int i,j;
// for output design of tic tac toe
for(i=0;i<6;i++){
for(j=0;j<8;j++){
if((i==3 || i==1) && (j!=2 && j!=5)){
printf("_");
}
else if((i==2 || i==0 || i==4 || i==5) && (j!=2 && j!=5)){
if(i==0 || i==2 || i==4)
printf("%c",a[i][j]);
else
printf(" ");
}
else{
printf("|");
}
}
printf("n");
}
}
int data(int x){
char c;
int r,choice,test=0;
(flag==1)?(c='X'):(c='O');
switch(x){
case 1: r=check(0,0);if(r!=0)break;(a[0][0]=c);break;
case 2: r=check(0,3);if(r!=0)break;(a[0][3]=c);break;
case 3: r=check(0,6);if(r!=0)break;(a[0][6]=c);break;
case 4: r=check(2,0);if(r!=0)break;(a[2][0]=c);break;
case 5: r=check(2,3);if(r!=0)break;(a[2][3]=c);break;
case 6: r=check(2,6);if(r!=0)break;(a[2][6]=c);break;
case 7: r=check(4,0);if(r!=0)break;(a[4][0]=c);break;
case 8: r=check(4,3);if(r!=0)break;(a[4][3]=c);break;
case 9: r=check(4,6);if(r!=0)break;(a[4][6]=c);break;
default:
printf("INVALID DATAn");
}
if(r!=0){
if(flag==1){
printf("nEnter your new choice:");
scanf("%d",&choice);
data(choice);
}
else{
data(r);
}
}
}
int check(int c,int d){
int i,j,empty=1;
if(flag==1){
if(a[c][d]=='X' || a[c][d]=='O'){
printf("nt!!!tEntered location already contains the datat!!! n");
return 1;
}
else{
return 0;
}
}
else{
if(a[c][d]=='X' || a[c][d]=='O'){
goto computer;
}
return 0;
}
computer:
for(i=0;i<=4;i+=2){
for(j=0;j<=6;j+=3){
if(a[i][j]!='X' && a[i][j]!='O'){
return empty;
}
empty++;
}
}
}int logic(int f){
if(f==1){
if((a[0][0]=='X'&&a[0][3]=='X'&&a[0][6]=='X')||(a[2][0]=='X'&&a[2][3]=='X'&&a[2][6]=='X')||(a[4][0]=='X'&&a[4][3]=='X'&&a[4][6]=='X')||(a[0][0]=='X'&&a[2][0]=='X'&&a[4][0]=='X')||(a[0][3]=='X'&&a[2][3]=='X'&&a[4][3]=='X')||(a[0][6]=='X'&&a[2][6]=='X'&&a[4][6]=='X')||(a[0][0]=='X'&&a[2][3]=='X'&&a[4][6]=='X')||(a[0][6]=='X'&&a[2][3]=='X'&&a[4][0]=='X'))
{
return 1;
}
else return 0;
}else if(f==2){
if((a[0][0]=='O'&&a[0][3]=='O'&&a[0][6]=='O')||(a[2][0]=='O'&&a[2][3]=='O'&&a[2][6]=='O')||(a[4][0]=='O'&&a[4][3]=='O'&&a[4][6]=='O')||(a[0][0]=='O'&&a[2][0]=='O'&&a[4][0]=='O')||(a[0][3]=='O'&&a[2][3]=='O'&&a[4][3]=='O')||(a[0][6]=='O'&&a[2][6]=='O'&&a[4][6]=='O')||(a[0][0]=='O'&&a[2][3]=='O'&&a[4][6]=='O')||(a[0][6]=='O'&&a[2][3]=='O'&&a[4][0]=='O'))
{
return 1;
}
else return 0;
}
}
void welcome_design(){
char start;
printf("nntttt______________________________________________________________n");
printf("tttt**************************************************************nn");
printf("ntttt---tWELCOME TO TIC TOE GAMEt---nnn");
printf("ttttt | | n");
printf("ttttt X | | n");
printf("ttttt___|___|___n");
printf("ttttt | | n");
printf("ttttt | X | n");
printf("ttttt___|___|___n");
printf("ttttt | | n");
printf("ttttt | | X n");
printf("ttttt | | n");
printf("nntttt______________________________________________________________n");
printf("tttt**************************************************************nn");
printf("nttEnter 'y' to start the game and 'n' to exit : ");
scanf("%c",&start);
if(start=='n'){
exit(0);
}
}
     
 
what is notes.io
 

Notes.io is a web-based application for taking notes. You can take your notes and share with others people. If you like taking long notes, notes.io is designed for you. To date, over 8,000,000,000 notes created and continuing...

With notes.io;

  • * You can take a note from anywhere and any device with internet connection.
  • * You can share the notes in social platforms (YouTube, Facebook, Twitter, instagram etc.).
  • * You can quickly share your contents without website, blog and e-mail.
  • * You don't need to create any Account to share a note. As you wish you can use quick, easy and best shortened notes with sms, websites, e-mail, or messaging services (WhatsApp, iMessage, Telegram, Signal).
  • * Notes.io has fabulous infrastructure design for a short link and allows you to share the note as an easy and understandable link.

Fast: Notes.io is built for speed and performance. You can take a notes quickly and browse your archive.

Easy: Notes.io doesn’t require installation. Just write and share note!

Short: Notes.io’s url just 8 character. You’ll get shorten link of your note when you want to share. (Ex: notes.io/q )

Free: Notes.io works for 12 years and has been free since the day it was started.


You immediately create your first note and start sharing with the ones you wish. If you want to contact us, you can use the following communication channels;


Email: [email protected]

Twitter: http://twitter.com/notesio

Instagram: http://instagram.com/notes.io

Facebook: http://facebook.com/notesio



Regards;
Notes.io Team

     
 
Shortened Note Link
 
 
Looding Image
 
     
 
Long File
 
 

For written notes was greater than 18KB Unable to shorten.

To be smaller than 18KB, please organize your notes, or sign in.