平均值

平均值

Problem Description

现有二个正整数a和b,设a、b均不超过64位无符号数的取值范围,输出其平均值的整数部分(舍去小数)。

Input

2个整数

Output

输出2个整数的平均数

Sample Input

5 6

Sample Output

5

分析:

这主要是可能出现溢出的问题,超过long long int  的数据范围,所以但是最后结果是没有超过的,因此需要控制好中间量的大小就好了。

 1 #include<stdio.h>  
 2     int main()  
 3     {   unsigned _int64 a,b;
 4     while(scanf("%I64u %I64u",&a,&b)!=EOF )
 5     {    
 6        
 7      if(a%2==0&b%2==0)
 8      { a=a/2;
 9        b=b/2;
10        printf("%I64u
",a+b);}
11      else {
12           a=a/2;
13        b=b/2;
14        printf("%I64u
",a+b+1);}
15 
16     }
17     return 0;
18 } 
View Code
原文地址:https://www.cnblogs.com/gznb/p/11212844.html