include stdio include stdlib include math double f1 double double f2 d

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
double f1(double);
double f2(double);
double integ(double(*)(double),double,double);
int n=35;
int main(void)
{
printf("first integral %lf\n",integ(f1,-1,3));
printf("second integral %lf\n",integ(f2,1,5));
system("pause");
return 0;
}
double integ(double(*f)(double),double a,double b)
{
double rez=0,h,i;
h=(b-a)/n;
rez = 0.5*(f(a) + f(b));
for (i=1; i < n; i++)
{
rez +=f(a + i*h);
}
return rez*=h;
}
double f1(double x)
{
return 1/(3*x*x-2*x+4);
}
double f2(double x)
{
return cos(x)/1+sin(x)*sin(x);
}