/* varargs.c - variable arguments example */

#include <stdarg.h>
#include <stdio.h>

int Sum(int n, ...)
{
	int i, sum = 0;
	va_list nums;

	va_start(nums,n);  /*  This is a macro call */
	for( i = 1 ; i <= n ; i++)
		sum += va_arg(nums, int);

	va_end(nums);
	
	return sum;
}

int main()
{
	printf("%d\n",Sum(0));
	printf("%d\n",Sum(1, 17));
	printf("%d\n",Sum(3, 1, -4,5));
	return 0;
}

/* things to try:
 * - write a version of Sum where the one arg given, an int, is the
 *   first of the numbers to sum, and the last is zero.
 * - cogitate on how printf works
 */

