39、给定程序MODI1.C中函数 fun 的功能是:计算
S = f(-n) + f(-n+1) +…+ f(0) + f(1) + f(2) +…+ f(n)的值。例如,当n为5时,函数值应为:10.407143。f(x)函数定义如下:
┌(x+1)/(x-2) x>0 且 x≠2
f(x) = ┤0 x=0 或 x=2
└(x-1)/(x-2) x<0
请改正程序中的错误,使程序能输出正确的结果。
注意:不要改动main函数,不得增行或删行,也不得更改程序的结构!
#include #include /************found************/
f( double x)
{
if (x == 0.0 || x == 2.0)
return 0.0;
else if (x < 0.0)
return (x -1)/(x-2);
else
return (x +1)/(x-2);
}
double fun( int n )
{ int i; double s=0.0, y;
for (i= -n; i<=n; i++)
{y=f(1.0*i); s += y;}
/************found************/
return s
}
main ( )
{
printf("%f\n", fun(5) );
}
| 广告合作:400-664-0084 全国热线:400-664-0084 Copyright 2010 - 2017 www.my8848.com 珠峰网 粤ICP备15066211号 珠峰网 版权所有 All Rights Reserved
|