#include <stdarg.h>
#include <iostream>
using namespace std;
int Sum(int a, ...)
{
int sum = 0, variable = a;
va_list list;
va_start(list, a);
while (variable != -1)
{
sum += variable;
variable = va_arg(list, int);
}
va_end(list);
return sum;
}
void main()
{
cout<<"The sum is " <<Sum(1,2,3,4,-1)<<endl;
}
#include <iostream>
using namespace std;
int Sum(int a, ...)
{
int sum = 0, variable = a;
va_list list;
va_start(list, a);
while (variable != -1)
{
sum += variable;
variable = va_arg(list, int);
}
va_end(list);
return sum;
}
void main()
{
cout<<"The sum is " <<Sum(1,2,3,4,-1)<<endl;
}