optional arguments: unlimited number of parameters
#include <stdarg.h>
unsigned int min( unsigned int first, ... )
{
int minarg, arg;
va_list argptr; // Pointer to optional arguments
if( first == 0)
return 0;
va_start( argptr, first);
minarg = first;
while( (arg = va_arg(argptr, unsigned int) ) != 0)
if( arg < minarg)
minarg = arg;
va_end (argptr);
return minarg;
}
#include <iostream>
using namespace std;
int main()
{
cout << "The minimum of : 1 2 3 4 5 " << "is:" << min(1,2,3,4,5)
<< endl;
return 0;
}
Related examples in the same category