c code for tic tac toe game to evaluate winner

c code for tic tac toe game to evaluate winner. Zero cross(tic tac toe) game is very easy to understand and most interesting game. This is two player game, for which one marks zero and other marks cross in the matrix provided of 3 * 3. We evaluate the winner by finding the matrix diagonal, or rows or columns of same character. If that happens then, the same will win.This c program provides a part of code for c code for tic tac toe. you can also see the list of game programming in c :

c code for tic tac toe game to evaluate winner.

#include<stdio.h>
#include<conio.h>

int main()
{
    printf(" ********** Zero One Match Result ************* \n");
    int a[3][3]={{0,1,0},
                 {1,1,1},
                 {0,0,1}};

                 for(int i=0; i<3; i++)
                 {
                         for(int j=0; j<3; j++)
                         {
                                 printf("%d ",a[i][j]);
                         }
                         printf("\n");
                 }       

                 for(int i=0; i<3; i++)
                 {
                         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]))
                         {
                                printf("  winner is : %d",a[1][1]);
                                getch();
                                return0;
                         }

            for(int i=0; i<3; i++)
            {
                   if(a[i][0]==a[i][1] && a[i][0]==a[i][2])
                   {
                          printf(" winner is : %d",a[i][0]);
                          getch();
                          return0;
                   }
                   elseif(a[0][i]==a[1][i] && a[1][i]==a[2][i])
                   {
                          printf(" winner is : %d", a[0][i]);
                          getch();
                          return0;
                   }
                   else
                   {
                   }
            }
            printf("Match draws");
}            
getch();
}

Output :

c code for tic tac toe
c code for tic tac toe

7 thoughts on “c code for tic tac toe game to evaluate winner”

  1. But this is pre defined .the program I tried to create this game was different ….that is where we ask the user to give the box num

    1. True deeksha, but the aim was to find the concept of evaluating the winner. You can extend the same program to ask from user input.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>