给定程序MODI1 C中函数fun的功能是:计算
S=f(-n)+f(-n+1)+.....+f(0)+f(1)+f(2)+...+f(n)
的值。例如当n为5时,函数值应为:
10.407143。fx)函数定义如下:
#include <stdio.h>
#include <math.h>
/************found************/
double 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));
}