consolidate all repos to one for archive
This commit is contained in:
23
semester_2/programiranje_2/primeri/Example30/main.cpp
Normal file
23
semester_2/programiranje_2/primeri/Example30/main.cpp
Normal file
@@ -0,0 +1,23 @@
|
||||
#include <iostream>
|
||||
#include <stdarg.h>
|
||||
|
||||
// function with variable number of arguments (...)
|
||||
int sum (int stev, ...) {
|
||||
va_list args; // variable arguments list
|
||||
int arg;
|
||||
int k, vsota=0;
|
||||
va_start(args, stev); //set the last parameter before variable arguments list
|
||||
for (k=0; k<stev; k++) {
|
||||
arg = va_arg(args, int); // take one argument from variable arguments list
|
||||
vsota += arg;
|
||||
}
|
||||
va_end(args); //End using variable argument list
|
||||
return vsota;
|
||||
}
|
||||
|
||||
int main() {
|
||||
std::cout << sum(5, 10, 20, 30, 40, 50) << std::endl;
|
||||
std::cout << sum(3, 11, 12, 13) << std::endl;
|
||||
return 0;
|
||||
}
|
||||
|
Reference in New Issue
Block a user