小学数学中我们就学过一种简单的求解两个整数平均数的算法(a+b)/2,当然它同样适用于我们的C语言
#include<stdio.h>
#include<stdlib.h>
int main() {
int a = 10;
int b = 20;
printf("%d\n", (a + b) / 2);
system("pause");
return 0;
}
但是这种方法有弊端,我们都知道int是4个字节也就是32个比特位如果a和b的数加起来超过×××所能容纳的数字,我们就无法得到a和b的平均值
#include<stdio.h>
#include<stdlib.h>
int main() {
int a = 2000000000;
i