问答题
下列给定程序中,函数fun的功能是:求S的值。
S=(2
2
/(1×3))×(4
2
/(3×5))×(6
2
/(5×7))×…×(2k)
2
/((2k-1)×(2k+1))
例如,当k为10时,函数的值应为1.533852。
请改正程序中的错误,使它能得出正确的结果。
注意:不要改动main函数,不得增行或删行,也不得更改程序的结构!
试题程序:
#include<stdlib.h>
#include<conio.h>
#include<stdio.h>
#include<math.h>
/********found********/
double fun(int k)
{
int n;float s,w,p,q;
n=1;
s=10;
while(n<=k)
{
w=2.0*n;
P=w-1.0;
q=w+1.0;
s=s*w*w/p/q;
n++;
}
/********found********/
return s
}
void main()
{system("CLS");
printf("%f/n",fun(10));
}