A20!
B19!
C1!+2+…19!
D1!+2!+…20!
第1题:
下列给定程序中,函数fun()的功能是:根据以下公式求n的值,并作为函数值返回。例如,给指定精度的变量eps输入 0.0005时,应当输出Pi=3.140578。
n/2=1+1/3+1/3*2/5+1/3*2/5*3/7+1/3*2/5*3/7*4/9……
请改正程序中的错误,使它能得出正确的结果。
注意:不要改动main函数,不得增行或删行,也不得更改程序的结构。
试题程序:
include <conio.h>
include <stdio.h>
include <math.h>
double fun(double eps)
{double s,t; int n=t;
s=0.0;
/*************found**************/
t=1;
/*************found**************/
while(t>eps)
{ s+=t;
t=t*n/(2*n+1);
n++;
}
/*************found**************/
return (s);
}
main()
{ double x;
printf("\nPlease enter a precision: ");
scanf("%1f",&x);
printf("\nPi=%1f\n ",fun(x));
}
第2题:
有以下程序 main() { int b[3][3]={0,1,2,0,1,2,0,1,2},i,j,t=1; for(i=0;i<3;i++) for(j=i;j<=i;j++)t=t+b[i][b][j][j]]; printf("%d\n",t); } 程序运行后的输出结果是( )
A.3
B.4
C.1
D.9
第3题:
假如n是正数,下列函数的功能是: def f(n): t=1 s=0 for i in range(1,n+1): t=t*i s=s+t return s
A.计算1!+2!+...+n!,!表示阶乘
B.计算1!+2!+...+(n+1)!,!表示阶乘
C.计算n!,!表示阶乘
D.计算(n+1)!,!表示阶乘
第4题:
若有如下程序: int sub() {static int n=1; int x=1; x*=n;n++; return x; } main() {int n,t=1; for(n=1;n<6;n++)t*=sub(); printf("%d\n",t); } 则程序运行后的输出结果是( )
A.15
B.120
C.34560
D.-30976
第5题:
T(n) = T(n-1) + n ,T(1)=1,则 T(n) =()
A.Ω(n^2)
B.n(n+1)/2
C.O(n^2)
D.θ(n^2)