📄 long_kutar.cpp
字号:
#include<iostream.h>
#include<math.h>
#include<iomanip.h>
double f(double x,double y);
double f(double x,double y)
{
double w;
w=y-2*x/y;
return w;
}
void main()
{
double x,x1,y,y1,y2,k1,k2,k3,k4,h;
int i,n;
cout<<"请输入x,y和h的值:"<<endl;
cout<<"x=";
cin>>x;
cout<<"y=";
cin>>y;
cout<<"h=";
cin>>h;
n=(y-x)/h;
cout<<"n="<<n<<endl;
for(i=1;i<=n;i++)
{
x1=x+h;
k1=f(x,y);
k2=f(x+0.5*h,y+0.5*h*k1);
k3=f(x+0.5*h,y+0.5*h*k2);
k4=f(x+h,y+h*k3);
y1=y+(k1+2*k2+2*k3+k4)*h/6;
x=x1;
y=y1;
y2=sqrt(1+2*x);
cout<<"x="<<x<<setw(8)<<"y="<<setprecision(6)<<y1<<setw(8)<<"y*="<<setprecision(6)<<y2<<endl;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -