#include<stdio.h>
#include<math.h>
int main()
{
float integral(float(*p)(float),float,float,int);
float fsin(float);
float a,b,(*p)(float),c;int n=20;
printf("input the a and b:");
scanf("%f %f",&a,&b);
p=fsin;
c=integral(*p,a,b,n);
printf("the end is:%f",c);
return 0;
}
float integral(float(*p)(float x),float a,float b,int n)
{
int i;
float s=0,h,x;
h=(b-a)/n;
x=a;
for(i=1;i<=n;i++)
{
x=x+h;
s=s+(*p)(x)*h;
}
return(s);
}
float fsin(float x)
{
return sin(x);
}
#include<math.h>
int main()
{
float integral(float(*p)(float),float,float,int);
float fsin(float);
float a,b,(*p)(float),c;int n=20;
printf("input the a and b:");
scanf("%f %f",&a,&b);
p=fsin;
c=integral(*p,a,b,n);
printf("the end is:%f",c);
return 0;
}
float integral(float(*p)(float x),float a,float b,int n)
{
int i;
float s=0,h,x;
h=(b-a)/n;
x=a;
for(i=1;i<=n;i++)
{
x=x+h;
s=s+(*p)(x)*h;
}
return(s);
}
float fsin(float x)
{
return sin(x);
}