1、源程序
#include "stdio.h"
#include "math.h"
float f(double x)
{
if(x==0.0||x==2.0)
return x;
else if(x>0.0)
return (x+1)/(x-2);
else return (x-1)/(x-2);
}
double fun(int a)
{
int i;
double y,s=0.0;
for(i=-a;i<=a;i++)
{
y=f(1.0*a);
s+=y;
}//for
return s;
}
int main()
{
printf("\n%d",fun(12));
}
2、程序简单,只是体现一种思想,即递推迭代。但是它的这种函数分层,功能模块化、独立化的思想,值得我们平时在编程时注意的。
3、还有两个数相乘或除时,结果的精度向精度大的方向靠拢。
y=f(1.0*a);
这种技巧我们可以留意一下的。
4、乘、除号两边为整型时,结果为整型 ,有一方为浮点数时,则结果为浮点数,也就是说结果向更加精确化的方向看齐。
9、S=f(-n)+f(-n+1)+......+f(0)+f(1)+......+f(n)
猜你喜欢
转载自blog.csdn.net/hopegrace/article/details/104605116
今日推荐
周排行