Skip to content

Commit

Permalink
naval recursivo
Browse files Browse the repository at this point in the history
  • Loading branch information
rafaeltakano committed Apr 1, 2018
1 parent cacbdc0 commit 9aa93ed
Showing 1 changed file with 44 additions and 4 deletions.
48 changes: 44 additions & 4 deletions naval.c
Original file line number Diff line number Diff line change
@@ -1,11 +1,31 @@
#include <stdio.h>
#include <stdlib.h>

void main(){
int cont = 0;

int verifica(char **matriz, int numero, int aux){
int p,q;
scanf("%d",&p);
scanf("%d",&q);
if(matriz[p-1][q-1] == '#'){
cont++;
}
//
if(aux < numero){
aux++;
return(verifica(matriz,numero,aux));
}
else{
return(printf("%d\n",cont));
}
}

int main(){
char **matriz;
int m,n;
int jogadas;
int i;
int m,n; //tamanho da matriz//
int jogadas; //numero de jogadas//
int aux = 1; //contador aux de jogadas feitas//
int i,j;
//capturando o numero de linhas e colunas para matriz//
scanf("%d",&m);
scanf("%d",&n);
Expand All @@ -14,4 +34,24 @@ void main(){
for(i=0; i<m; i++){
matriz[i] = malloc(n * sizeof(char));
}
//preencher a matriz de chars '.' ou '#'//
for(i=0; i<m; i++){
for(j=0; j<n; j++){
scanf(" %c",&matriz[i][j]);
}
}
/*mostrando a matriz
for(i=0; i<m; i++){
for(j=0; j<n; j++){
printf("m[%d][%d] = %c\n",i,j,matriz[i][j]);
}
}*/
//pegando o numero de jogadas//
scanf("%d",&jogadas);
//verificando//
verifica(matriz,jogadas,aux);
//
free(matriz);
matriz = NULL;
return(EXIT_SUCCESS);
}

0 comments on commit 9aa93ed

Please sign in to comment.