We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
Here is my code... I know it could be better, but it works.
#include<stdio.h>#include<stdlib.h>#include<stdarg.h>intsum(intcount,...){va_listarguments;ints=0;va_start(arguments,count);for(inti=0;i<count;i++){s+=va_arg(arguments,int);}va_end(arguments);returns;}intmax(intcount,...){va_listarguments;intmx=0;inttemp;va_start(arguments,count);for(inti=0;i<count;i++){temp=va_arg(arguments,int);if(temp>mx){mx=temp;}}va_end(arguments);returnmx;}intmin(intcount,...){va_listarguments;intmn=1000001;inttemp;va_start(arguments,count);for(inti=0;i<count;i++){temp=va_arg(arguments,int);if(temp<mn){mn=temp;}}va_end(arguments);returnmn;}intmain(){printf("The sum is %d\n",sum(4,1,2,3,4));printf("The max is %d\n",max(3,11,31,14));printf("The min is %d\n",min(3,100,16,114));return0;}
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Variadic functions in C
You are viewing a single comment's thread. Return to all comments →
Here is my code... I know it could be better, but it works.