<\/span><\/h2>\n\n\n\nVariadic functions are functions which take a variable number of arguments. In C programming, a variadic function will contribute to the flexibility of the program that you are developing.<\/p>\n\n\n\n
The declaration of a variadic function starts with the declaration of at least one named variable, and uses an ellipsis as the last parameter, e.g.<\/p>\n\n\n\n
int printf(const char* format, ...);<\/pre>\n\n\n\nIn this problem, you will implement three variadic functions named sum()<\/strong><\/em>, min()<\/em><\/strong> and max()<\/strong><\/em> to calculate sums, minima, maxima of a variable number of arguments. The first argument passed to the variadic function is the count of the number of arguments, which is followed by the arguments themselves.<\/p>\n\n\n\n<\/span>Input Format<\/strong><\/span><\/h2>\n\n\n\n- The first line of the input consists of an integer number_of_test_cases<\/em><\/strong>.<\/li>
- Each test case tests the logic of your code by sending a test implementation of 3, 5 and 10 elements respectively.<\/li>
- You can test your code against sample\/custom input.<\/li>
- The error log prints the parameters which are passed to the test implementation. It also prints the sum, minimum element and maximum element corresponding to your code.<\/li><\/ul>\n\n\n\n
<\/span>Constraints<\/strong><\/span><\/h2>\n\n\n\n- 1 <= Number_of_test_cases<\/em> <= 50<\/strong><\/li>
- 1 <= element<\/em> <= 1000000<\/strong><\/li><\/ul>\n\n\n\n
<\/span>Output Format<\/strong><\/span><\/h2>\n\n\n\n“Correct Answer” is printed corresponding to each correct execution of a test implementation.”Wrong Answer” is printed otherwise.<\/p>\n\n\n\n
Sample Input 0<\/strong><\/p>\n\n\n\n1<\/pre>\n\n\n\nSample Output 0<\/strong><\/p>\n\n\n\nCorrect Answer\nCorrect Answer\nCorrect Answer<\/pre>\n\n\n\n<\/span>Solution – Variadic Functions in C <\/strong><\/span><\/h2>\n\n\n\nint sum (int count,...) {\n int sum=0;\n va_list values;\n va_start(values,count);\n for(int i=0;i<count;i++){\n sum+=va_arg(values,int);\n }\n va_end(values);\n return sum;\n\n}\n\nint min(int count,...) {\n int min=MAX_ELEMENT,test; \n va_list values;\n va_start(values,count);\n for(int i=0;i<count;i++){\n test=va_arg(values,int);\n if(min>test){\n min=test;\n } \n }\n va_end(values);\n return min;\n\n}\n\nint max(int count,...) {\n int max=MIN_ELEMENT,test;\n va_list values;\n va_start(values,count);\n for(int i=0;i<count;i++){\n test=va_arg(values,int);\n if(max<test){\n max=test;\n } \n }\n va_end(values);\n return max;\n}\n\n<\/pre>\n\n\n\n