1 #include <stdio.h> 2 #include <stdarg.h> 3 /*用sum_series() 求一列数的指定个数的数和(5个数字的和)*/ 4 double sum_series(int num, ...); 5 6 int main() 7 { 8 double s; 9 s = sum_series(5, 0.5, 0.25, 0.125, 0.06254, 2.0); 10 printf("Sum of series is %2.8f. ", s); 11 return 0; 12 } 13 14 double sum_series(int num, ...) 15 { 16 double sum= 0.0, t; 17 va_list a; 18 va_start(a, num); 19 for(; num; num--) 20 { 21 t= va_arg(a, double); 22 sum= sum+ t; 23 } 24 va_end(a); 25 return sum; 26 }