下面pi函数的功能是根据以下的公式,返回满足精度ε要求的π值。请填空。 double pi(double eps) {double s=
下面pi函数的功能是根据以下的公式,返回满足精度ε要求的π值。请填空。
double pi(double eps)
{double s=0.0,t=1.0;
intn;
for(______;t>eps;n++)
{s+=t;
t=-n*t/(2*n+1):}
return(2.0*______);}
下面pi函数的功能是根据以下的公式,返回满足精度ε要求的π值。请填空。
double pi(double eps)
{double s=0.0,t=1.0;
intn;
for(______;t>eps;n++)
{s+=t;
t=-n*t/(2*n+1):}
return(2.0*______);}
第1题
double pi(double eps) { double s=0.0,t=1.0; int n; for(【 】 ;t>eps;n++) { s+=t; t=n* t/(2*n+1); } return(2.0* 【 】 ); }
第2题
函数pi的功能是根据以下公式近似求得的: pi*pi/6=1+1/(2*2)+1/(3*3)+…+1/(n*n) 请在下面的函数中填空,完成求pi的功能。 include<math.h> double pi(long n) { doubles=0.0,long i; for(i=1;i<=n;i++)s=s+ 【 】 ; return(sqrt(6*s)); }
第3题
在给定程序中,函数fun的功能是:根据以下公式求π值,并作为函数值返回。
例如,给指定精度的变量eps输入0.0005时,应当输出Pi=3.140578。 请改正程序中的错误,使它能得出正确结果。 注意:不要改动main函数,不得增行或删行,也不得更改程序的结构。 include include include double fun(double eps) {double s,t; int n=1; s=0.0; /************found************/ t=0; while(t>eps) {s+=t; t=t*n/(2*n+1); n++; } /************found************/ return(S); } main() {double x; printf("\nPlease enter a preciSion:")j scanf(”%1f”,&x); printf("\neps=%1f,Pi=%1f\n\n",x,fun(x)); )
第4题
函数pi的功能是根据以下近似公式求π值:
请在下面的函数中填空,完成求π的功能。 include <math.h> double pi(long n) { double s = 0.0; long i; for(i = 1;i <= n; i++) s = s +【 】; return (sqrt(6*s)); }
第5题
函数pi的功能是根据以下近似公式求π值: (π*π)/6=1+1/(2*2)+1/(3*3)+…+1(n*n) 现在请你在下面的函数中填空,完成求π的功能。 include “math.h" { double s=0.0; long i; for(i=1;i<=n;i++)s=s+ 【 】 ; return(sqrt(6*s)); }
第6题
函数fun的功能是:根据以下公式求p的值,结果由函数值返回。m与n为两个正数且要求m>n。
例如:m=12,n=8时,运行结果应该是495.000000。请在题目的空白处填写适当的程序语句,将该程序补充完整。 include<conio.h> include<stdio.h) float fun(int m,int n) { int i; double p=1.0; for(i=1;i<=m;i++)【 】; for(i=1;i<=n;i++)【 】; for(i=1;i<=m-n;i++)p=p/i; return P;} main() { clrscr(); printf("p=%f\n",fun(12,8));}
第7题
根据下面类中Give 函数的原型和注释写出它的类外定义。
class Strings {
char *s; // 指向动态分配的字符串数组空间
int n; // 记录字符串长度
public:
Strings(char*str); // 构造函数,利用str 字符串长度初始化n,
// 利用str 字符串初始化s 所指的字符串空间
Strings(Strings& str); // 拷贝构造函数
Strings& Give(Strings& str); // 实现str 赋值给*this 的功能并返回*this
Strings Uion(Strings& str); // 实现*this 和str 中的字符串合并的
// 功能,把合并结果存入临时对象并返回
int Lenth() {return n;} // 返回字符串长度
void Print() {cout<<s<<endl;} // 输出字符串
};
第9题
下面程序的功能是:根据输入的整数x和n,利用函数fact实现求。 例如:输入:2,3 输出=8 请在程序中的横线上填入正确的内容,将程序补充完整。 /* c7-1.c 利用函数fact实现求x的n次方*/ #include "stdio.h" int main() { long int fact(long x,long n) ; /*声明fact函数*/ long int x ; long int n; printf("please enter X and N(>=0): "); scanf("%ld,%ld", &x, &n ); printf("%ld,%ld=%ld",x,n, (1) ); /*调用fact函数 */ return 0; } long int fact(long int x, long int n) /*定义fact函数求xn */ { long int i,s; (2) ; /*求累积变量的初始化*/ if (n= =0) return 0; for(i=1; i<=n; i++) *用循环实现xn* s="s*x;" (3) ; *返回结果xn*>
第10题
函数viod fun(float * sn,int n)的功能是:根据以下公式计算S,计算结果通过形参指针sn传回;n通过形参传入,n的值大于等于0。请填空。 s=1-1/3+1/5-1/7+…1/(2n+1) void fun(float * sn,int n) { floats=0.0,w,f=-1.0; int i=0; for(i=0;i<=n;i+ +) { f=【 】 * f; w=f/(2i+1); s+ +=w; } 【 】 =s; }