#include <stdlib.h>
#include <time.h>
int maior(int n, int A[]){
if(n==1)
return A[0];
if(maior(n-1, A)<A[n-1])
return A[n-1];
else
return maior(n-1,A);
}
int main(){
int n, i;
printf("Tamanho do vetor: ");
scanf("%d", &n);
int A[n];
srand( (unsigned)time(NULL) );
for(i=0; i<n; i++){
A[i] = rand();
printf("%d\n", A[i]);
}
printf("O maior valor é: %d", maior(n, A));
}
This code is O (n)?
And is it the best recursive code to look for the highest value within a vector?