📄 龙贝格.cpp
字号:
# include <iostream.h>
# include <math.h>
double f(double n)
{
double a=sin(n);
double b=a/n;
return b;
}
void main ()
{
double a,b,c,s,h,x,t1,t2,c1,c2,r1,r2,s1,s2;
cout<<"Please put into three numbers:\n";
cin>>a>>b>>c;
int k=1,i=1,j=0;
h=b-a;
t1=(f(a)+f(b))*h/2;
while (i)
{
if (j==1)
{
k=k+1;
h=h/2;
t1=t2;
s1=s2;
}
j=0;
s=0;
x=a+h/2;
while (x<b)
{
s=s+f(x);
x=x+h;
}
t2=t1/2+h*s/2;
s2=t2+(t2-t1)/3;
if (k==1)
{
j=1;
continue;
}
else
{
c2=s2+(s2-s1)/15;
if (k==2)
{
c1=c2;
j=1;
continue;
}
else
{
r2=c2+(c2-c1)/63;
if (k==3)
{
r1=r2;
c1=c2;
j=1;
continue;
}
else
if (r2-r1<c && r1-r2<c)
{
cout<<r2<<endl;
i=0;
}
else
{
r1=r2;
c1=c2;
j=1;
continue;
}
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -