c语言实现两个数的平均值

来源:互联网 发布:apache cgi bin 编辑:程序博客网 时间:2024/06/05 10:18
#include<stdio.h>int  average(int *a, int *b){    int x = *a;    int y = *b;    //return (x + y) >> 1;    //return (x + (x - y)) >> 1;  //a>b    return (x & y) + (x^y) >> 1;}int main(){    int a = 0;    int b = 0;    printf("please enter the number>");    scanf("%d%d", &a, &b);    int ret=average(&a, &b);    printf("average=%d\n", ret);    return 0;}