Advertisement
STANAANDREY

var arg sum

Mar 28th, 2023
702
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.27 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdarg.h>
  3.  
  4. int sum(int n, ...) {
  5.   va_list va;
  6.   va_start(va, n);
  7.   int s = 0;
  8.   for (int i = 0; i < n; i++) {
  9.     s += va_arg(va, int);
  10.   }
  11.   va_end(va);
  12.   return s;
  13. }
  14.  
  15. int main() {
  16.   printf("%d\n", sum(3, 1, 2, 3));
  17.   return 0;
  18. }
  19.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement