Advertisement
Guest User

Untitled

a guest
Nov 14th, 2018
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.62 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <stdarg.h>
  4. enum type { Int, Double,End };
  5. void max(...) {
  6. type type;
  7. int intsum = 0;
  8. double doublesum = 0;
  9. int i;
  10. va_list z;
  11. va_start(z, type);
  12. while ((type = va_arg(z,type)) != End)
  13. if (type == Int) {
  14. int value = va_arg(z, int);
  15. intsum += value;
  16. }
  17. while ((type = va_arg(z,type)) != End)
  18. if (type == Double){
  19. double value = va_arg(z, double);
  20. doublesum += value;
  21. }
  22. printf("%d\n", intsum);
  23. printf("%f\n",doublesum);
  24. va_end(z);
  25. }
  26. int main() {
  27. max(Int,5,7,1,7,3,4,5,End);
  28. max(Double,5.12,6.66,7.77,8.88,9,78,End);
  29. return 0;
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement