hi there, it's been a long time !
After some stuff under GP32, i'm coming back for the GP2X
i'm looking of a way of returning the number of the same value joined in an array.
I don't want to use a recursive fonction because of the stack overheap.
Here is my C code trying to do that with loop but something is missing.
Any ideas ?
here the result. As you can see it's not working.
After some stuff under GP32, i'm coming back for the GP2X
i'm looking of a way of returning the number of the same value joined in an array.
I don't want to use a recursive fonction because of the stack overheap.
Here is my C code trying to do that with loop but something is missing.
Any ideas ?
Code:
#include <stdio.h>
#include <math.h>
int mur[14][14],i,j;
int somme=0;
int x=0; int y=0;
int main (int argc, const char * argv[]) {
// insert code here...
printf("retourne le nombre de valeur adjacente dans un tableau\n");
int ligne, colonne;
//remplissage du tableau
for ( i=0;i<15;i++)
for (j=0;j<15;j++)
mur[i][j]=rand()%5;
//affichage du tableau
for ( i=0;i<15;i++)
for (j=0;j<15;j++)
printf("%i\t",mur[i][j]);
while(ligne !=16)
{
printf("\nligne:");
scanf("%i",&ligne);
printf("\ncolone:");
scanf("%i",&colonne);
printf("%d",mur[ligne][colonne],"\n");
printf("\n");
test(ligne,colonne,mur[ligne][colonne]);
printf("\nest présent :%i",somme);
}
}
test ( int ligne, int colonne, int valeur )
{
for ( i=0;i<15;i++){
for (j=0;j<15;j++){
if (mur[ligne+x][colonne]==valeur){x++;somme++;}
if (mur[ligne-x][colonne]==valeur){x++;somme++;}
if (mur[ligne][colonne+y]==valeur){y++;somme++;}
if (mur[ligne][colonne-y]==valeur){y++;somme++;}
}
}
return somme;
}
here the result. As you can see it's not working.