#include<iostream.h>
#include<math.h>
#define f(x) (sin(x))
#define m 100
#define e 0.00001
void main()
{
int i;
double n,a,b;
double h,T1,T2,S;
cout<<"Please input the begin and end of x (a<=x<=b):";
cout<<"a=";cin>>a;
cout<<"b=";cin>>b;
n=m;
h=(b-a)/n;
for(i=1,S=0;i<=n-1;i++)
{
S=S+f(a+i*h);
}
T2=h*(1/2*f(a)+S+1/2*f(b));
T1=T2+100;
while((T1-T2)>3*e||(T1-T2)<-(3*e))
{
T1=T2;
h=h/2;
for(i=1,S=0;i<=n;i++)
{
S=S+h*f(a+(2*i-1)*h);
}
T2=T1/2+S;
n=2*n;
}
cout<<"Output the T2:"<<T2<<endl;
cout<<"Output the n:"<<n<<endl;
}