#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll N = 1e3;
double f1(double x)
{
double ans = 1.0 / (1.0+ sin(x) * sin(x) );
return ans;
}
double f2(double x)
{
return x * log10(x);
}
double f3(double x)
{
if(x==0.0)
return 1;
else
return sin(x) / x;
}
//复合梯形公式,把积分函数作为指针传入的函数中
double CTF(double a, double b, int n, double (*fun)(double))
{
double h = (b - a) / n;
double ans = 0;
for(int i=1; i<=n-1; i++)
{
double x = a + i * h;
ans = ans + fun(x);
}
ans = ans * 2;
ans = ans + fun(a) + fun(b);
ans = ans * h / 2;
return ans;
}
//复合Simpson积分公式
double CSF(double a, double b, int n, double (*fun)(double))
{
int m = n / 2;
double h = (b- a) / n;
double ans = 0;
for(int i=1; i<= m-1; i++)
{
double x = a + 2 * i * h;
ans = ans + fun(x);
}
ans = ans * 2;
double temp = 0;
for(int i=1; i<=m; i++)
{
double x = a + (2*i - 1) * h;
temp = temp + fun(x);
}
temp = temp * 4;
ans = ans + temp;
ans = (ans + fun(a) + fun(b)) * h / 3;
return ans;
}
int main()
{
double a, b;
cin>>a>>b;
int n;
cin>>n;
double ans = CTF(a, b, n, f1);
double ans2 = CSF(a, b, n, f1);
printf("f1复合梯形积分公式结果:%12.8f\n", ans);
printf("f1复合Simpson积分公式: %12.8f\n", ans2);
double a1, a2;
int nn;
cin>>a1>>a2;
cin>>nn;
double res = CTF(a1, a2, nn, f2);
double res2 = CSF(a1, a2, nn, f2);
printf("f2复合梯形积分公式结果:%12.8f\n", res);
printf("f2复合Simpson积分公式: %12.8f\n", res2);
return 0;
}