#include void lerMatriz(char matriz[][3], int size){ scanf("%c %c %c\n", &matriz[0][0], &matriz[0][1], &matriz[0][2]); scanf("%c %c %c\n", &matriz[1][0], &matriz[1][1], &matriz[1][2]); scanf("%c %c %c", &matriz[2][0], &matriz[2][1], &matriz[2][2]); } void imprimeMatriz(char matriz[][3], int size){ for (int i = 0; i < size; i++){ for (int j = 0; j < size; j++){ printf("%c ", matriz[i][j]); } printf("\n"); } } int ganhador(char celula){ if (celula == 'x'){ printf("x ganhou\n"); return 1; }else if (celula == 'o'){ printf("o ganhou\n"); return 1; } return 0; } void verificaEstado(char matriz[][3], int size){ int countMoves = 0; int estado = 0; for (int i = 0; i < size; i++){ for (int j = 0; j < size; j++){ if (matriz[i][j] != '-'){ countMoves++; } } } //vericar linhas for (int i = 0; i < size; i++){ if (matriz[i][0] == matriz[i][1] && matriz[i][1] == matriz[i][2]){ estado = ganhador(matriz[i][0]); } } //vericar colunas for (int j = 0; j < size; j++){ if (matriz[0][j] == matriz[1][j] && matriz[1][j] == matriz[2][j]){ estado = ganhador(matriz[0][j]); } } //diagonal principal if (matriz[0][0] == matriz[1][1] && matriz[1][1] == matriz[2][2]){ estado = ganhador(matriz[0][0]); } //diagonal secundaria if (matriz[0][2] == matriz[1][1] && matriz[1][1] == matriz[2][0]){ estado = ganhador(matriz[0][2]); } if (estado == 0 && countMoves == 9){ printf("empate\n"); }else if (estado == 0 && countMoves < 9){ printf("em jogo\n"); } } int main(){ int size = 3; char matriz[size][size]; lerMatriz(matriz, size); verificaEstado(matriz, size); //imprimeMatriz(matriz, size); return 0; }