fork(1) download
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. int qtdseq(int matriz[10][12], int lin, int col, int num) {
  5. if (lin >= 10 || col >= 12 || lin < 0 || col < 0) return 0;
  6. if (matriz[lin][col] != num) return 0;
  7. if (num == 1) return 1;
  8.  
  9. return qtdseq(matriz, lin, col + 1, num - 1)
  10. + qtdseq(matriz, lin, col - 1, num - 1)
  11. + qtdseq(matriz, lin + 1, col, num - 1)
  12. + qtdseq(matriz, lin - 1, col, num - 1);
  13. }
  14.  
  15. int main() {
  16. int mat[10][12] = {
  17. {34, 45, 18, 56, 98, 33, 42, 67, 6, 11, 40, 10},
  18. {88, 59, 23, 34, 44, 11, 34, 61, 43, 1, 3, 9},
  19. {33, 32, 31, 22, 33, 77, 12, 11, 34, 98, 72, 74},
  20. {40, 50, 21, 17, 15, 52, 45, 10, 9, 32, 27, 30},
  21. { 4, 14, 32, 11, 22, 33, 44, 65, 8, 52, 76, 12},
  22. { 6, 13, 56, 91, 22, 45, 22, 18, 7, 45, 23, 44},
  23. { 8, 9, 20, 87, 2, 5, 56, 5, 6, 5, 4, 3},
  24. {12, 99, 23, 4, 3, 81, 42, 4, 8, 4, 77, 2},
  25. {98, 97, 96, 95, 38, 1, 2, 3, 56, 3, 56, 1},
  26. { 3, 1, 7, 45, 93, 96, 1, 46, 1, 2, 41, 23}
  27. };
  28.  
  29. printf("Quantidade de sequĂȘncias encontradas = %d\n", qtdseq(mat, 2, 6, 12));
  30. }
Success #stdin #stdout 0s 4276KB
stdin
Standard input is empty
stdout
Quantidade de sequências encontradas = 4