I have a task to make two functions: max_el function that needs to return the pointer to the largest element in the array; and min_el function that needs to return the pointer to the smallest element in the array. I have this so far, and for some examples it works, for some it crashes and for some the output isn't right. I really don't know where I messed up.
int *max_el(int *p1, int *p2){
int max,i;
for(i=p1; i<p2; i++){
if(*p1>*p2){
max=*p1;
}
p2++;
}
return p1;
}
int *min_el(int *p1, int *p2){
int min,i;
for(i=p1; i<p2; i++){
if(*p1<*p2){
min=*p1;
}
p2++;
}
return p1;
}
iis an integer.p1is a pointer to an integer. So doingi=p1is wrong. Makes no sense. You probably wantito be a pointer to int