您的位置:首页 > 其它

不用(a+b)/2的方法,求两个数的平均值。

2015-10-17 14:14 225 查看
第一种方法:
#include<stdio.h>
#include<stdlib.h>
int main()
{
int a,b;
scanf("%d%d",&a,&b);
printf("%d",(a&b)+((a^b)>>1));
system("pause");
return 0;
}
第二种方法:
#include<stdio.h>
#include<stdlib.h>
int main()
{
int a,b;
scanf("%d%d",&a,&b);
printf("%d",a-((a-b)>>1));
system("pause");
return 0;
}

本文出自 “liveyoung” 博客,转载请与作者联系!
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: