include stdio include stdlib include math define 200 double funcia_1 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
34
35
36
37
38
39
40
41
42
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#define N 200
double funcia_1(double x);
double funcia_2(double y);
double Integral(double a, double b, double (*funcia)(double));
int main(void)
{
printf("Integral 1 = %lf\n",Integral(2,7,funcia_1));
printf("Integral 2 = %lf\n",Integral(-3,1.5,funcia_2));
system("PAUSE");
return 0;
}
double funcia_1(double x)
{
return sqrt(x*x-2)/x;
}
double funcia_2(double y)
{
return sin(y)*sin(y)*sin(y);
}
double Integral(double a, double b, double (*funcia)(double))
{
double h,sum;
int i;
sum=funcia(a);
h=(b-a)/N; /*шаг*/
for(i=1;i<N;i++)
if((i+1)%2==0)
sum+=4*funcia(a+h*i);
else
sum+=2*funcia(a+h*i);
sum+=funcia(b);
return sum*=(h/3);
}