题目内容:
下列给定程序中,函数proc()的功能是:求s的值。设S=(22/(1*3))*(42/(3*5))*(62/(5*7))
*…*(2k)2/((2k-1)*(2k+1))
例如,当k为20时,函数的值应为1.551 759。
请修改程序中的错误,使它能得出正确的结果。
注意:不要改动main()函数,不得增行或删行,也不得更改程序的结构。
试题程序:
#include<stdio.h>
#include<conio.h>
#include<stdio.h>
#include<math.h>
//****found**** proc(int k)
{
int n;float s,w,p,q;
n=1;
s=1.0;
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",proc(20));
}
参考答案:
答案解析: