In the main function you first need to create an integer arr
Solution
Precondition in this program is that we have to declare an int array of 10 elements and an integer that can store the value returned by the getMax() function.
#include <stdio.h>
/* function declaration */
int getMax(int arr[], int size);
int main () {
/* an int array with 10 elements */
int arr[10],position,i;
printf(\"Enter the elements of array\");
for(i=0;i<10;i++)
{
scanf(\"%d\",&arr[i]);
}
/* pass base address of array as an argument */
position = getMax( arr, 10) ;
printf(\"Position of max element is %d\", position);
return 0;
}
//function definition
int getMax(int arr[], int size) {
int maximum,c,location;
maximum = arr[0];
for (c = 1; c < size; c++)//loop for finding maximum element
{
if (arr[c] > maximum)
{
maximum = arr[c];
location = c;
}
}
printf(\"maximum element%d\",maximum);
//returns the position of maximum element in the array
return location;
}
Post Condition is that the returned value is the index of maximum value found in array.
