I need to find and print the index of the highest value in the array using pointers. My professor said it's possible to do with only the defined integers below (no counters or other valuables).
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
int main()
{
int array[100], size, *MAX, *pi;
srand(time(NULL));
MAX = array;
printf("Insert array size:\n");
scanf("%d", &size);
for(pi=array; pi<array+size; pi++)
{
*pi = ( rand()%100 ) + 1;
}
printf("\nArray elements:\n");
for(pi=array; pi<array+size; pi++)
printf("%d\t", *pi);
for(pi=array+1; pi<array+size; pi++)
if(*pi>*MAX)
{
MAX = pi;
}
printf("\n\nMax is %d.", *MAX);
}
pimax - niz. But unfortunately whatnizis, is unknown in your code.MAXis already the pointer to the max element, not its value. So its index isMAX - arraybutnizis undefined.