之前,博主也讲过一片关于位运算的应用题目,只出现一次的数,有兴趣的可以查看哦:https://blog.csdn.net/ly_6699/article/details/83930964
题目描述:
不使用(a + b)/ 2这种方式,求两个数的平均值。
主要思想:
可以使用位运算,将整体向右移一位即可实现
完整代码
#define _CRT_SECURE_NO_WARNINGS 1
#include <stdlib.h>
#include <stdio.h>
int main()
{
int a = 0;
int b = 0;
printf("请输入你要求的数;");
scanf("%d%d", &a,& b);
int ret = ((a + b) >> 1);
printf("%d\n", ret);
system("pause");
return 0;
}