// ConsoleApplication1.cpp : 定义控制台应用程序的入口点。
//P70
#include "stdafx.h"
#include "math.h"
#include <iostream>
using namespace std;
int main()
{
#define f(x) (sin(x)/x)
double a, b, e,h,T1,T2,S,x,S1,S2,C1,C2,R1,R2;
cout << "请输入a,b,e:" << endl;
cin >> a >> b >> e;
h = b - a;
T1 = h / 2 * (f(a)+f(b));
int k = 1;
do
{
S = 0;
x = a + h / 2;
do
{
S += f(x);
x += h;
} while (x < b);
T2 = T1 / 2 + h / 2 * S;
S2 = T2 + 1 / 3 * (T2 - T1);
if (k = 1);
C2 = S2 + 1 / 15*(S2 - S1);
if (k = 2);
R2 = C2 + 1 / 63*(C2 - C1);
if (k = 3);
} while (fabs(R2-R1)>=e);
cout << R2;
return 0;
}
//P70
#include "stdafx.h"
#include "math.h"
#include <iostream>
using namespace std;
int main()
{
#define f(x) (sin(x)/x)
double a, b, e,h,T1,T2,S,x,S1,S2,C1,C2,R1,R2;
cout << "请输入a,b,e:" << endl;
cin >> a >> b >> e;
h = b - a;
T1 = h / 2 * (f(a)+f(b));
int k = 1;
do
{
S = 0;
x = a + h / 2;
do
{
S += f(x);
x += h;
} while (x < b);
T2 = T1 / 2 + h / 2 * S;
S2 = T2 + 1 / 3 * (T2 - T1);
if (k = 1);
C2 = S2 + 1 / 15*(S2 - S1);
if (k = 2);
R2 = C2 + 1 / 63*(C2 - C1);
if (k = 3);
} while (fabs(R2-R1)>=e);
cout << R2;
return 0;
}