Code:
#include <stdio.h>
#define N 6
int main(void){
int i,k,v[N];
printf("Input the vector:\n");
for(i=0;i<N;i++){
printf("Element %d:",i+1);
scanf("%d",&v[i]);}
printf("\n");
maxpos(v[N]);
return 0;
}
int maxpos(int vec[]){
int k,max,pos;
max=0;
for(k=0;k<N;k++){
if(vec[k]>vec[k+1]){
max=vec[k];
pos=k;}
}
printf("\n");
printf("Maximum:%d;\nPos:%d;",max,pos);
system("pause");
}
When I run this code, regardless of the vector I input, the outcome is invariably the same: Maximum:1 Pos:4
I've check the code up and down but I can't find anything wrong with it.
Can anyone tell me what I'm doing wrong here?
Appreciate.