Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<stdio.h>
- int board [4] [4];
- void initailize()
- {
- int i,j;
- for(i=1;i<=3;i++)
- for(j=1;j<=3;j++)
- board [i][j]=2;
- printf("\nThe board is initialized");
- }
- void print_board(){
- printf("\n\n");
- int i,j;
- for(i=1;i<=3;i++)
- {
- for(j=1;j<=3;j++)
- if(j!=3)
- {
- if (board [i][j]==2)
- printf(" |");
- else if( board [i][j]==3)
- printf(" X |");
- else
- printf(" 0 |");
- }
- else{
- if (board [i][j]==2)
- printf(" ");
- else if( board [i][j]==3)
- printf(" X ");
- else
- printf(" 0 ");
- }
- if(i!=3){
- printf("\n-----------\n");
- }
- }
- printf("\n\n");
- }
- int Make2(){
- if (board[2][2]==2)
- return 5;
- else if (board[1][2]==2)
- return 2;
- else if (board[2][1]==2)
- return 4;
- else if (board[2][3]==2)
- return 6;
- else
- return 8;
- }
- void Go(){
- int player,position;
- printf("\n enter 3 players X:");
- printf("\n enter 5 for player::");
- scanf("%d",&player);
- printf("\n enter the position:");
- scanf("%d",&position);
- if(position==1)
- board[1][1]=player;
- else if(position==2)
- board[1][2]=player;
- else if(position==3)
- board[1][3]=player;
- else if(position==4)
- board[2][1]=player;
- else if(position==5)
- board[2][2]=player;
- else if(position==6)
- board[2][3]=player;
- else if(position==7)
- board[3][1]=player;
- else if(position==8)
- board[3][2]=player;
- else if(position==9)
- board[3][3]=player;
- }
- int main(){
- int choice,position;
- while(1){
- printf("\n enter 1 for initialization");
- printf("\n enter 2 for make2");
- printf("\n enter 3 for go");
- printf("\n enter 10 for print board");
- printf("\n enter 100 for exit");
- printf("\n enter your choice");
- scanf("%d",&choice);
- if(choice==100)
- break;
- switch(choice){
- case 1:initailize();break;
- case 2: position=Make2();
- printf("\n Make2 returns %d\n",position);
- break;
- case 3: Go();break;
- case 10:print_board();
- break;
- default: printf("\n your choice is wrong!!\n");
- }
- }
- }
Add Comment
Please, Sign In to add comment