ADDVALUE.C
资源名称:C.rar [点击查看]
上传用户:qq5388545
上传日期:2022-07-04
资源大小:29849k
文件大小:1k
源码类别:
界面编程
开发平台:
C/C++
- #include <stdio.h>
- #include <stdarg.h>
- int add_values(int value, ...)
- {
- va_list argument_ptr;
- int result = 0;
- if (value != 0)
- {
- result += value;
- va_start(argument_ptr, value);
- while ((value = va_arg(argument_ptr, int)) != 0)
- result += value;
- va_end(argument_ptr);
- }
- return(result);
- }
- void main(void)
- {
- printf("Sum of 3 is %dn", add_values(3, 0));
- printf("Sum of 3 + 5 is %dn", add_values(3, 5, 0));
- printf("Sum of 3 + 5 + 8 is %dn", add_values(3, 5, 8, 0));
- printf("Sum of 3 + 5 + 8 + 9 is %dn", add_values(3, 5, 8 , 9, 0));
- }