fork download
  1. #include <cstdarg>
  2. #include <iostream>
  3. #include <limits>
  4.  
  5.  
  6.  
  7. int smallestOf(const int count, const int val1, ... ) { /* I use val1 to determine the template type */
  8. va_list args;
  9. va_start(args, val1);
  10. int smallestVal = std::numeric_limits<int>::max();
  11. for(int i = 0; i < count; i++) {
  12. int nextVal = va_arg(args, int);
  13. std::cout << "nextVal: " << nextVal << std::endl;
  14. if(nextVal < smallestVal) smallestVal = nextVal;
  15. }
  16. va_end(args);
  17. return smallestVal;
  18. }
  19.  
  20.  
  21. int main() {
  22. std::cout << "Smallest value: " << smallestOf(3, 10, 20, 30) << std::endl;
  23. }
Success #stdin #stdout 0s 15232KB
stdin
Standard input is empty
stdout
nextVal: 20
nextVal: 30
nextVal: 360499552
Smallest value: 20