0
Boa am doing the following exercise in C language
I made the following code and I don’t understand why it’s not working...
int maior_subida(int *tab, int dim) {
int i, pos=0, diferenca=0, diferenca_anterior=0;
for (i = 0; i < dim; i++) {
diferenca = ((*(tab+i+1))-(*(tab+i)));
if (diferenca > diferenca_anterior){
pos = (i + 1);
diferenca_anterior=diferenca;
}
}
return pos;}
int main(){
int tabela[10]={31,3309,43,5,25461,10,9,7,537,1}, posicao;
posicao=maior_subida(tabela,10);
printf("O elemento que tem maior diferenca do anterior e o que esta na posicao: %d\n",posicao);}
Thanks for the answer, really not repaired in the possibility of bufferOverflow, already fixed my algorithm and the program works correctly. Regarding what I said in point 2, I am learning to manipulate pointers so the choice to use *tab instead of tab[0]
– Droopy