#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
double sum_series(int num, ...);
int main(int argc, char *argv[])
{
double d;
d = sum_series(4, 0.5, 0.25, 0.125, 0.6254);
printf("Sum of series is %f.\n", d);
system("pause");
return 0;
}
double sum_series(int num, ...)
{
double sum = 0.0, t;
va_list argptr;
va_start(argptr, num);
for(; num; num--)
{
t = va_arg(argptr, double);
sum = sum + t;
}
va_end(argptr);
return sum;
}
|