seb - 6 months ago 46

C Question

In the library in C/C++, the function fmin(x,y) returns the minimum value of the two arguments x and y, as documented for instance in the C++ reference.

However, is there a similar function fminimum(a,b,c,...x,y,z) available that finds the minimum of three or more arguments of the same data type?

**EDIT**: sorry for the confusion. This question is restricted only to C, so no C++

Answer

The old fashioned way...

```
int arr[] = { 1, 3, 6, 100, 50, 72 };
int min_array( int arr[], int len )
{
int min = arr[0];
for ( int i = 1; i < len; i++ )
if ( arr[i] < min )
min = arr[i];
return min;
}
```