Find out the max num from input varargs,the function prototype:int max_list(int values,...);"-1" indicates the end of a input of varargs.
- #include <stdio.h>
-
#include <stdarg.h>
-
-
int max_list(int values,...)
-
{
-
va_list var_arg;
-
int max = 0,tmp = 0;
-
-
va_start(var_arg,values);
-
-
while(( tmp = va_arg(var_arg,int)) >= 0 )
-
{
-
if(max < tmp)
-
{
-
max = tmp;
-
}
-
}
-
-
va_end(var_arg);
-
-
return max;
-
}
-
-
int main()
-
{
-
int max_arg = 0;
-
-
max_arg = max_list(1,9,3,5,-1);
-
-
printf("the max_arg is:%d\n",max_arg);
-
-
return 0;
-
}
阅读(1128) | 评论(0) | 转发(0) |