0
I need help to solve the following problem:
"Write a function that receives an arrangement of whole as parameter and returns the index of the largest element of the arrangement. Ex : int intMax(int *a, int tamanho)
"
I made a part of the code and it does what was asked, only not the way it was asked:
int recebeArray(){
int mtrx[5];
int count, maior;
for(count=0; count<5; count++){
printf("Digite um numero \n");
scanf("%d",&mtrx[count]);
if(mtrx[count] > mtrx[count-1]){
maior=mtrx[count];
}
}
printf("O maior numero e' : %d",maior);
}
int main(){
recebeArray();
}
Wouldn’t it be better to
i
offor
start right at1
?– Isac
@Isac: You’re right! It’s not necessary to sweep the array from the first element (
i = 0
), scan can start from the second element (i = 1
), if he exists.– Lacobus
@Isac: Really, if you consider the first element as the biggest one today, it doesn’t make sense to go through it again.
– Marcelo Junior