Welcome to collectivesolver - Programming & Software Q&A. A website you can trust. All programs tested and works. Contact: aviboots(AT)netvision.net.il
Bonsai Trees

Liquid Web Managed Dedicated Server: RAID 1 SSD with 16GB of RAM minimum! 24/7 On-Site Heroic Support! Industry-Leading SLA!

BlueHost Web Hosting

Ecommerce Software - Best Ecommerce Platform Made for You - Free Trial

Ecommerce Software - Best Ecommerce Platform Made for You - Free Trial

getflywheel wordpress hosting


Liquid Web Cloud VPS Hosting

8,954 questions

12,356 answers

573 users

How to use terminator value to determine the end of va_list in C

1 Answer

0 votes
#include <stdio.h>
#include <stdarg.h>
#include <math.h>

double sum(double n, ...) 
{
  double sum = 0;
  va_list va;

  va_start(va, n);
  
  for (; !isnan(n); n = va_arg(va, double)) 
    sum += n;

  va_end(va);

  return sum;
}

int main (void) 
{
    printf("%g\n", sum(3.14, 2.3, 1.7, 6.8, 4.2, NAN));
    printf("%g\n", sum(0.1, 0.2, 0.5, 0.0313, 0.09, 0.7, NAN));
  
    return 0;
}

    
/*
run:
 
18.14
1.6213
   
*/

 




answered Aug 16, 2017 by avibootz
...