#include <iostream>#include<stdio.h>using namespacestd;intMain () {//-1 No one wins 0:o win 1: X Winintsize;printf ("0 means "party a", 1 means "Party B" \ n");p rintf ("Please enter the size of the matrix \ n"); while(SCANF ("%d", &size) = =1){intboard[ -][ -];intNum_of_o;intnum_of_x;intresult =-1;intI, J; for(i =0; i < size; i++) for(j =0; J < size; J + +) {scanf ("%d", &board[i][j]);}//Check Row for(i =0; I < Size&&result = =-1; i++) {Num_of_o= Num_of_x =0; for(j =0; J < size; J + +){if(Board[i][j] = =1) {num_of_x++;}Else if(Board[i][j] = =0) {Num_of_o++;}}if(Num_of_o = =size) {Result=0;}Elseif(num_of_x = =size) {Result=1;}}//Check Columnif(Result = =-1){ for(j =0; J < Size&&result = =-1; J + +) {Num_of_o= Num_of_x =0; for(i =0; i < size; i++){if(Board[i][j] = =1) {num_of_x++;}Elseif(Board[i][j] = =0) {Num_of_o++;}}if(Num_of_o = =size) {Result=0;}Elseif(num_of_x = =size) {Result=1;}}}//Check Positive DiagonalNum_of_o = Num_of_x =0; for(i =0; i < size; i++){if(Board[i][i] = =1) {num_of_x++;}Elseif(Board[i][i] = =0) {Num_of_o++;}}if(Num_of_o = =size) {Result=0;}Elseif(num_of_x = =size) {Result=1;}//Check for anti-diagonalNum_of_o = Num_of_x =0; for(i =0; i < size; i++){if(Board[i][size-1-I] = =1)//Inverse Diagonal Calculation method{num_of_x++;}Elseif(Board[i][size-1-I] = =0) {Num_of_o++;}}if(Num_of_o = =size) {Result=0;}Elseif(num_of_x = =size) {Result=1;}if(Result = =-1) {printf ("Sorry, no one wins Oh! \ nto fight Again! \ n");}Elseif(Result = =0) {printf ("Congratulations!!! Party a WINS \ n");}Elseif(Result = =1) {printf ("Congratulations!!! Party B wins.");} printf ("Please enter the size of the matrix \ n");}return 0;}
C language Two-dimensional array board game