language: C (gcc-4.7.2)
date: 323 days 17 hours ago
link:
visibility: public
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#include <stdio.h>
#include <stdarg.h>
 
int calculateTotal(int n, ...)
{
 
    //declartion of a datatype that would hold all arguments
    va_list arguments;
 
    //starts iteration of arguments
    va_start (arguments, n);
 
    //declarion of initialization for 'for loop'
    //declation of accumulator
    int i = 0;
    int localTotal = 0;
 
    for(i; i < n; i++)
    {
        //va_arg allows access to an individual argument
        int currentArgument = va_arg(arguments, int);
        localTotal += currentArgument;
    }
 
    //freeing the declaration of the datatype that holds the information
    va_end(arguments);
 
    return localTotal;
}
 
int main()
{
    int total = calculateTotal(2,7,8);
    printf("Total > %d\n",total);
 
    return 0;
}