include stdio include math double f1 double return pow cos 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 <math.h>
double f1(double x){
return 1./pow(cos(x),4);
}
double f2(double x){
return 2*x+x*x;
}
double Integral(double f (double), int np, int vp, int N){
double x;
double sum=0;
x = np+(vp-np)/(double)N;
while(x<vp){
sum+=f(x);
x+=(vp-np)/(double)N;
}
sum+=(f(np)+f(vp))/2;
sum*=(vp-np)/(double)N;
return sum;
}
int main(){
printf("Intergal 1 = %f\n", Integral(f1,2,5,35));
printf("Intergal 2 = %f\n", Integral(f2,-2,2,35));
return 0;
}