只要求平均数而以,不一定要求和。。。
#include<stdio.h>
/*for the average of odd number between n to m */
int main()
{
int n,m,ave;
while(scanf("%d %d",&n,&m)!=EOF)
//
n<=m
{
ave=oddave(n,m);
printf("%d\n",ave);
}
}
int oddave(int n,int m)
{
if((n%2 == 0) && (m%2 == 1))
{
return (n+1+m)/2;
}
else if((n%2 == 1) && (m%2 == 0))
{
return (n+m-1)/2;
}
else
//(((n%2 == 1) && (m%2 == 1))||((n%2 == 0) && (m%2 == 0)))
{
return (n+m)/2;
}
}