//stdarg宏求平均值
#include <stdio.h>
#include <stdarg.h>
int average(int num, ...)
{
int i = 0;
int sum = 0;
va_list arg;
va_start(arg, num);
for (i = 0; i < num; i++)
{
sum = sum + va_arg(arg, int);
}
return sum / num;
}
int main()
{
int ret = average(4, 5, 2, 5, 4);
printf("%d\n", ret);
return 0;
}
//第二种:
#include <stdio.h>
int bit(int x, int y)
{
return (x & y) + ((x ^ y) >> 1);
}
int main()
{
int a = 0;
int b = 0;
int ret;
printf("请输入俩数:\n");
scanf("%d %d", &a, &b);
ret = bit(a, b);
printf("%d\n", ret);
return 0;
}
转载于:https://blog.51cto.com/10706198/1706492