214,479 views
14 votes
14 votes
Write a C function arrayMinimum( ) that accepts an integer valued array a along with its size arraySize as parameters and returns the smallest array element.

User Arunas Bart
by
2.3k points

1 Answer

6 votes
6 votes

Answer:

int arrayMinimum(int* arr, int arraySize){

int result = arr[0];

for (int i = 0; i < arraySize; i++){

if (arr[i] < result)

result = arr[i];

}

return result;

}

Step-by-step explanation:

This function takes a integer array and it's size as parameters. It defines an integer variable result, which is initialized with the value of the first element of the array. The function then iterates through the array and checks if the current index's value is smaller than result. If it's smaller than result, it sets result to the element, if it isn't it continues at normal. At the end of the function, the function returns result, which represents the smallest array element.

User Ashwin Singh
by
3.5k points