Advertisement
hmcristovao

lista05_exerc16

Oct 3rd, 2012
321
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.25 KB | None | 0 0
  1. #include <stdio.h>
  2. int main() {
  3.    char velha[3][3] = {{'0','X','0'},
  4.                        {'X','0','X'},
  5.                        {'X',' ','0'}};
  6.  
  7.    // compara as linhas:
  8.    if(velha[0][0] == velha[0][1] && velha[0][1] == velha[0][2])
  9.       printf("O ganhador foi \'%c\'", velha[0][0]);
  10.    else if(velha[1][0] == velha[1][1] && velha[1][1] == velha[1][2])
  11.       printf("O ganhador foi \'%c\'", velha[0][0]);
  12.    else if(velha[2][0] == velha[2][1] && velha[2][1] == velha[2][2])
  13.       printf("O ganhador foi \'%c\'", velha[0][0]);
  14.    // compara as colunas:
  15.    else if(velha[0][0] == velha[1][0] && velha[1][0] == velha[2][0])
  16.       printf("O ganhador foi \'%c\'", velha[0][0]);
  17.    else if(velha[0][1] == velha[1][1] && velha[1][1] == velha[2][1])
  18.       printf("O ganhador foi \'%c\'", velha[0][0]);
  19.    else if(velha[0][2] == velha[1][2] && velha[1][2] == velha[2][2])
  20.       printf("O ganhador foi \'%c\'", velha[0][0]);
  21.    // compara as diagonais:
  22.    else if(velha[0][0] == velha[1][1] && velha[1][1] == velha[2][2])
  23.       printf("O ganhador foi \'%c\'", velha[0][0]);
  24.    else if(velha[0][2] == velha[1][1] && velha[1][1] == velha[2][0])
  25.       printf("O ganhador foi \'%c\'", velha[0][0]);
  26.    else
  27.       printf("Nao houve ganhador");
  28.    return 0;
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement