// ConsoleApplication1.cpp : 定义控制台应用程序的入口点。
//P101
#include "stdafx.h"
#include "math.h"
#include <iostream>
using namespace std;
int main()
{
#define f(x,y) (y-2*x/y)
double x0, x1, y0, y1, yp, yc,h, N,n;
cout << "请输入x0,y0,h,N:" << endl;
cin >> x0 >> y0 >> h >> N;
n = 1;
do
{
x1 = x0 + h;
yp = y0 + h* f(x0,y0);
yc = y0 + h* f(x1,yp);
y1 = (yp + yc) / 2;
cout << "x1=" << x1 << "\t" << "y1=" << y1 << endl;
n++;
x0 = x1;
y0 = y1;
} while (n!=N);
return 0;
}
//P101
#include "stdafx.h"
#include "math.h"
#include <iostream>
using namespace std;
int main()
{
#define f(x,y) (y-2*x/y)
double x0, x1, y0, y1, yp, yc,h, N,n;
cout << "请输入x0,y0,h,N:" << endl;
cin >> x0 >> y0 >> h >> N;
n = 1;
do
{
x1 = x0 + h;
yp = y0 + h* f(x0,y0);
yc = y0 + h* f(x1,yp);
y1 = (yp + yc) / 2;
cout << "x1=" << x1 << "\t" << "y1=" << y1 << endl;
n++;
x0 = x1;
y0 = y1;
} while (n!=N);
return 0;
}